Home > Database > Mysql Tutorial > body text

mysql tutorial: Backup using SELECT INTO

黄舟
Release: 2016-12-16 16:00:20
Original
3133 people have browsed it

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)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!