There are two ways to execute SQL commands at the command line. The first is to use the "-e" parameter to specify the SQL statement that needs to be executed, and the second way is through the pipe. The syntax and examples are as follows:
1,
| The code is as follows |
Copy Code |
Mysql_home/bin/mysql-u User name-p password-d database name-e "SQL statement" /usr/local/mysql/bin/mysql-uroot-p123456-dmysql-e "Select Host,user from User"; |
2,
| The code is as follows |
Copy Code |
echo "SQL statement" | Mysql_home/bin/mysql-u User name-p password-d database name echo "Select Host,user from User" | /usr/local/mysql/bin/mysql-uroot-p123456-dmysql |
The results of the above command execution are shown below. You can see from the diagram that the results of the two displays are somewhat different.
Usage scenarios are used more in scripts, such as periodic execution of stored procedures, load data infile, and deletion of old data.