Summary of several ways to execute SQL in mysql command line, mysqlsql
1. directly input SQL to execute
MySQL> select now ();
+ --------------------- +
| Now () |
+ --------------------- +
| 13:55:45 |
+ --------------------- +
1 row in set (0.00 sec)
2. Execute the compiled SQL script
Mysql> source H:/1. SQL
+ --------------------- +
| Now () |
+ --------------------- +
| 13:54:04 |
+ --------------------- +
1 row in set (0.00 sec)
3. select... into outfile method to execute SQL
Mysql> select now () into outfile 'H:/data/2. SQL ';
Query OK, 1 row affected (0.00 sec)
4. Run the mysql Command
H: \> mysql-uaHmin-p-e "select now ()"
Enter passworH :****
+ --------------------- +
| Now () |
+ --------------------- +
| 13:57:09 |
+ --------------------- +
5. Run the mysql command to execute the SQL statement and save the query result to the text.
A) execute simple SQL
Mysql-uaHmin-proot test-e "select now ()"-N> H:/work/target1.txt
If the SQL statement is too long, this method is not very suitable.
B) execute complex SQL statements
Complex SQL statements can be edited in advance and stored in text for execution.
H: \> mysql-uroot-pmypwH-h127.0.0.1-p3306 test <H:/work/source. SQL> H:/work/target.txt
By adding the last execution method to the scheduled task of the operating system, you can implement scheduled SQL Execution in mysql and save the execution results.
Reference: 3.5. Using mysql in Batch Mode in the official documentation
Http://dev.mysql.com/doc/refman/5.6/en/batch-mode.html
The above is a summary of all the methods for executing SQL statements in the mysql command line provided by xiaobian. I hope you can support more help ~