• Execute Mysql Command in Bash / Shell Script

    #!/bin/sh
    
    #Script to run automated sql queries
    
    #Declaring mysql DB connection 
    
    MASTER_DB_USER='username'
    MASTER_DB_PASSWD='password'
    MASTER_DB_PORT=3160
    MASTER_DB_HOST='mysql.hostname'
    MASTER_DB_NAME='mysqlDbName'
    
    #Prepare sql query
    
    SQL_Query='select * from tablename limit 10'
    
    #mysql command to connect to database
    
    mysql -u$MASTER_DB_USER -p$MASTER_DB_PASSWD -P$MASTER_DB_PORT -h$MASTER_DB_HOST -D$MASTER_DB_NAME <<EOF 
    $SQL_Query
    EOF
    echo "End of script"
  • 0 comments:

    Post a Comment

    FAVOURITE LINE

    To steal ideas from one is plagiarism. To steal from many is Research.

    ADDRESS

    Mumbai , Maharashtra

    EMAIL

    shikha.pathak6@gmail.com
    shikha.the.swt.pari@gmail.com

    Skype

    shikha_pari