Mysql saves the results to a file from a file running SQL statements to record the operation process (use of the tee command)

Source: Internet
Author: User
Tags log log

1. Sometimes we may need to record our operation on MySQL, when we are able to use the MySQL tee command

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

>mysql-u root-p--tee=c:\log.txt//Note there is no need to add an argument to the path

At this point we will record all the operation of the database on the Log.txt;

2) The second method is to use after linking the database

MySQL > Tee C:\log.txt//The operation behind this command is recorded in log

When you do not want to log log, you can use the Notee command, the operation after the command will no longer be recorded

MySQL > notee;



2. When we are querying a table. The results of the output can be very numerous. At this time it is very inconvenient to analyze on the console. We are able to export the results to file analysis

1) Directly use the console redirection function.

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; Turn off recording function

3) Sometimes you can also use SELECT * from TableName to outfile ' Finenane ';


3. Run the SQL statement in the external file

Method OneRun with the cmd command (under Windows, UNIX or Linux under its console)
"MySQL Bin folder" \mysql–uusername–ppassword–d database < "SQL script file path full name", Demo sample:
D:\mysql\bin\mysql–uroot–p123456-dtest<d:\test\ss.sql
Attention:
A, assuming that the use database is used in the SQL script file, the-d database option can ignore
B, if the "MySQL Bin folder" includes spaces, you need to include, such as: "C:\Program files\mysql\bin\mysql" –UUSERNAME–PPASSWORD–D database < "SQL script file path full name 】

Method TwoAfter entering MySQL console, run with the source command
Mysql>source "path full name of SQL script file" or mysql>\. "Path full name of SQL script file", Demo sample:
source D:\test\ss.sql or \. D:\test\ss.sql


Mysql saves the results to a file from a file running SQL statements to record the operation process (use of the tee command)

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.