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)