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