mysql教程:使用SELECT INTO进行备份

使用select into进行备份
使用select into进行备份与mysqldump很相似,同样是把数据库备份到一个指定的文件中。其结果文件只能被建立在mysql服务器上,而不是任何其他主机。select into语句的语法格式如下:
select … into outfile ‘path_and_filename’ ;
示例:
使用select into语句查询数据库“mr_mysql”中的“mr_gly”表,把该表备份到“d:gly.txt”目录下,文件的名称是“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)
下面的这些参数是select into语句的非默认参数。
[fields
[terminated by ‘ ‘ ]             //设置输出文件以什么作为分界标识
[enclosed by ” ]               //指定的字符包围了所有的域
[[optionally] enclosed by ” ]     //指定只有字符域被包括
[escaped by ”] ]
[lines terminated by ‘ ‘ ]          //设置长行的中断被什么字符代替
下面是应用了select into语句非默认参数的几个示例。
示例:
在每个域之间,默认的制表符被字符“|”代替。
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)
示例:
enclosed关键字用指定的字符“双引号”包围了所有的域。
mysql> select * from jtsr into outfile “d:user2.txt” fields terminated by ‘|’ enclosed by ‘”‘;
query ok, 5 rows affected (0.02 sec)
示例:
optionally关键字的使用,导致了只有字符域被双引号包括。
mysql> select * from jtsr into outfile “d:user3.txt” fields terminated by ‘|’ optionally enclosed by ‘”‘ ;
query ok, 5 rows affected (0.02 sec)
示例:
lines terminated的使用,使每行之间的中断被字符“ ”代替。
mysql> select * from jtsr into outfile “d:user4.txt” fields terminated by ‘|’ lines terminated by ‘ ‘ ;
query ok, 5 rows affected (0.02 sec)
示例:
综合使用这些参数。
mysql> select * from jtsr into outfile “d:user5.txt” fields terminated by ‘|’ optionally enclosed
by ‘”‘ lines terminated by ‘ ‘ ;
query ok, 5 rows affected (0.02 sec)
示例:
使用select语句中的条件进行备份。
mysql> select * from jtsr where id>3 into outfile “d:user6.txt” fields terminated by ‘|’ optionall
y enclosed by ‘”‘ lines terminated by ‘ ‘ ;
query ok, 2 rows affected (0.01 sec)
注意:在使用select into语句时,为备份的文件命名时切忌不要重写已存在的文件;在编写文件输出的位置时不要忘记使用换码符“”。

 以上就是mysql教程:使用SELECT INTO进行备份的内容,更多相关文章请关注PHP中文网(www.php.cn)!

© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享