Use SELECT INTO for backup
Use SELECT INTO for backup is very similar to MYSQLDUMP. It also backs up the database to a specified file. The result file can only be created on the MySQL server, not any other host. The syntax format of the SELECT INTO statement is as follows:
Select … into outfile 'path_and_filename' ;
Example:
Use the SELECT INTO statement to query the "mr_gly" table in the database "mr_mysql" and back up the table to "D:\gly.txt" directory, the name of the file is "gly.txt".
mysql> use mr_mysql
Database changed
mysql> select * from mr_gly into outfile "D:\gly.txt";
Query OK, 5 rows affected (0.00 sec)
The following parameters are non-default parameters for the SELECT INTO statement .Specifies that only character fields are included
[escaped by '\'] ]
[lines terminated by 'n' ] //Set what character should be used to replace long line breaks
The following are several examples of non-default parameters of the SELECT INTO statement. .
Example:
Between each field, the default tab character is replaced by the character "|".
mysql> use tpsc
Database changed
mysql> select * from jtsr into outfile "D:\user1.txt" fields terminated by '|' ;
Query OK, 5 rows affected (0.00 sec)
Example:
Enclosed keyword Surround all fields with the specified character "double quotes".
mysql> select * from jtsr into outfile "D:\user2.txt" fields terminated by '|' enclosed by '"';
Query OK, 5 rows affected (0.02 sec)
Example:
Use of Optionally keyword, As a result, only character fields are enclosed in double quotes.
mysql> select * from jtsr into outfile "D:\user3.txt" fields terminated by '|' optionally enclosed by '"' ;
Query OK, 5 rows affected (0.02 sec )
Example: The use of
lines terminated, so that the break between each line is replaced by the character "n".
mysql> select * from jtsr into outfile "D:\user4.txt" fields terminated by '|' lines terminated by 'n' ;
Query OK, 5 rows affected (0.02 sec)
Example:
Use these parameters comprehensively.
mysql> select * from jtsr into outfile "D:\user5.txt" fields terminated by '|' optionally enclosed
by ''' lines terminated by 'n' ;
Query OK, 5 rows affected (0.02 sec)
Example :
Use the conditions in the SELECT statement for backup.
mysql> select * from jtsr where id>3 into outfile "D:\user6.txt" fields terminated by '|' optionall
y enclosed by '"' lines terminated by ' n' ;
Query OK, 2 rows affected (0.01 sec)
Note: When using the SELECT INTO statement, do not overwrite the existing file when naming the backup file; do not forget to use replacement when writing the location of the file output Code character "".
The above is the mysql tutorial: using SELECT INTO for backup. For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!