When the terminal uses MySQL to execute the statement, we usually go to MySQL first and then execute the SQL statement inside.
For example:
mysql-urootmysql> use mydb;mysql> select * from user;..
If we need to monitor some of the tables and save the results of the executed query, we need to manually copy them to the file, which will affect productivity.
Terminal Execution SQL
Therefore, the following methods can be used, instead of entering MySQL, but directly in the terminal using the shell call MySQL Execute SQL statement.
MySQL provides the- e parameter for executing statements directly at the terminal and outputting them.
For example:
Mysql-uroot-e ' select * from Mydb.user '
When executing statements with MYSQL-E, you can join-V,-VV,-VVV parameters
- v shows the statement itself
-VV Increase the number of rows that display query results
-vvv Increase display execution time
Execution results write to file
With output redirection, you can save the results of the execution to a file.
For example:
Mysql-uroot-e ' select * from Mydb.user ' >/tmp/mydb_user.txt
After the terminal executes, the query results are saved to/tmp/mydb_user.txt.
When the terminal uses MySQL to execute the statement, we usually go to MySQL first and then execute the SQL statement inside.
For example:
mysql-urootmysql> use mydb;mysql> select * from user;..
If we need to monitor some of the tables and save the results of the executed query, we need to manually copy them to the file, which will affect productivity.
Terminal Execution SQL
Therefore, the following methods can be used, instead of entering MySQL, but directly in the terminal using the shell call MySQL Execute SQL statement.
MySQL provides the- e parameter for executing statements directly at the terminal and outputting them.
For example:
Mysql-uroot-e ' select * from Mydb.user '
When executing statements with MYSQL-E, you can join-V,-VV,-VVV parameters
- v shows the statement itself
-VV Increase the number of rows that display query results
-vvv Increase display execution time
Execution results write to file
With output redirection, you can save the results of the execution to a file.
For example:
Mysql-uroot-e ' select * from Mydb.user ' >/tmp/mydb_user.txt
After the terminal executes, the query results are saved to/tmp/mydb_user.txt.
This article explains how MySQL executes SQL at the terminal and writes the results to the file, and more about the PHP Chinese web.
Related recommendations in:
PHP uses a token bucket algorithm based on Redis for traffic control
Redis master-Slave synchronization, read and write separation settings related operations
Describes how MySQL rebuilds table partitions and preserves data