Facebooktwittergoogle_plusredditpinterestlinkedinmail

Shell script to run mysql query from command line without login into mysql command prompt.  You can use these shell script for quickly execution of MySQL query from a Linux Shell.
Method 1:

#!/bin/bash
#Script to run mysql query from command line
#Db Connection.
DB_USER='root'
DB_PASSWD='mypwd'
DB_NAME='mydb'
#Prepare sql query
QUERY='select * from employee'
#Command to connect db and execute the query.
MYSQL -u$DB_USER -p$DB_PASSWD -D$DB_NAME <<EOF
$QUERY
EOF
echo "End of script"

Parameter Description:
-u : Mysql User name.
-p : Mysql User Password.
-D : Name of the database.

Method 2:

#!/bin/bash

#Db Connection.
DB_HOST='127.0.0.1'
DB_USER='root'
DB_PASSWD='mypwd'
DB_NAME='mydb'
echo
mysql --host=$DB_HOST --user=$DB_USER --password=$DB_PASSWD $DB_NAME -e 'select * from employee;'
Run Mysql Query from Command Line Roopendra LinuxScripting,,,
Shell script to run mysql query from command line without login into mysql command prompt.  You can use these shell script for quickly execution of MySQL query from a Linux Shell. Method 1: #!/bin/bash #Script to run mysql query from command line #Db Connection. DB_USER='root' DB_PASSWD='mypwd' DB_NAME='mydb' #Prepare sql query QUERY='select * from employee' #Command to connect db and execute the...
Shell script to run mysql query from command line without login into mysql command prompt.  You can u<span style="color: #444444;">se these shell script for quickly execution of MySQL query from a Linux Shell.</span> <strong>Method 1:</strong> <pre>#!/bin/bash #Script to run mysql query from command line #Db Connection. DB_USER='root' DB_PASSWD='mypwd' DB_NAME='mydb' #Prepare sql query QUERY='select * from employee' #Command to connect db and execute the query. MYSQL -u$DB_USER -p$DB_PASSWD -D$DB_NAME <<EOF $QUERY EOF echo "End of script"</pre> <strong>Parameter Description:</strong> -u : Mysql User name. -p : Mysql User Password. -D : Name of the database.<strong>Method 2:</strong> <pre>#!/bin/bash#Db Connection. DB_HOST='127.0.0.1' DB_USER='root' DB_PASSWD='mypwd' DB_NAME='mydb' echo mysql --host=$DB_HOST --user=$DB_USER --password=$DB_PASSWD $DB_NAME -e 'select * from employee;'</pre>
(Visited 1,020 times, 34 visits today)
Facebooktwittergoogle_pluslinkedinrss