Mysql saves the result to a file and executes SQL statements from the file to record the operation process (using the tee command), sqltee

Source: Internet
Author: User

Mysql saves the result to a file and executes SQL statements from the file to record the operation process (using the tee command), sqltee

1. Sometimes we may need to record our mysql operation process. In this case, we can use the mysql tee command.

1) The first case is to use tee when connecting to the database.

> Mysql-u root-p -- tee = C: \ log.txt // note that no quotation marks are required for the path here.

At this time, all operations on the data warehouse will be recorded on log.txt;

2) The second method is to use

Mysql> tee C: \ log.txt // The operations after this command are recorded in the log

When you do not want to record logs, you can use the notee command. The operations following this command will not be recorded again.

Mysql> notee;



2. When we query a table, there may be many output results, which is inconvenient to analyze on the console. We can export the result to file analysis.

1) Use the redirection function of the console directly.

Mysql-u root-p-e "use mysql; show tables;"> C: \ log.txt

2) use the tee command;

Mysql> tee C: \ log.txt;

Mysql> use mysql;

Mysql> show tables;

Mysql> notee; // disable the record Function

3) Sometimes you can use select * from tableName into outfile 'finenane ';


3. Execute the SQL statement in the external file

Method 1Run the cmd command (unix or linux is on its console in windows)
[Mysql bin directory] \ mysql-u user name-p password-D database <[full name of the SQL script file path], example:
D: \ mysql \ bin \ mysql-uroot-p123456-Dtest <d: \ test \ ss. SQL
Note:
A. If the use database is used in the SQL script file, the-D database option can be ignored.
B. If the bin directory of Mysql contains spaces, use "" to include, for example, "C: \ Program Files \ mysql \ bin \ mysql "-u user name-p password-D database <[full name of the SQL script file path]

Method 2Log on to the mysql console and run the source command.
Mysql> source [full name of the SQL script file path] Or Mysql> \. [full name of the SQL script file path], for example:
Source d: \ test \ ss. SQL or \. d: \ test \ ss. SQL


Related Article

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.