How MySQL executes SQL at the terminal and writes the results to a file

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.