There are two ways to execute SQL commands under the command line. The first is to use the "-e" parameter to specify the SQL statement to be executed, and the second is to use the pipeline. Syntax and example: 1. MYSQL_HOMEbinmysql-u username-p password-D database name-esql statement usrlocalmysqlbinmysql-uroot-p123456-Dmysql
There are two ways to execute SQL commands under the command line. The first is to use the "-e" parameter to specify the SQL statement to be executed, and the second is to use the pipeline. Syntax and example: 1. MYSQL_HOME/bin/mysql-u username-p password-D database name-e "SQL statement"/usr/local/mysql/bin/mysql-uroot-p123456-Dmysql
There are two ways to execute SQL commands under the command line. The first is to use the "-e" parameter to specify the SQL statement to be executed, and the second is to use the pipeline. Syntax and example:
1. MYSQL_HOME/bin/mysql-u username-p password-D database name-e "SQL statement"/usr/local/mysql/bin/mysql-uroot-p123456-Dmysql- e "select host, user from user "; 2. 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 preceding command execution result is as follows. The results are different.
Use Cases are often used in scripts, such as regular execution of stored procedures, load data infile, and deletion of old data.
Original article address: Execute the mysql command through the command line. Thanks to the original author for sharing.