使用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 '\t' ] //设置输出文件以什么作为分界标识
[enclosed by '' ] //指定的字符包围了所有的域
[[optionally] enclosed by '' ] //指定只有字符域被包括
[escaped by '\\'] ]
[lines terminated by '\n' ] //设置长行的中断被什么字符代替
下面是应用了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的使用,使每行之间的中断被字符“\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)
示例:
综合使用这些参数。
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)
示例:
使用select语句中的条件进行备份。
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)
注意:在使用select into语句时,为备份的文件命名时切忌不要重写已存在的文件;在编写文件输出的位置时不要忘记使用换码符“\”。
以上就是mysql教程:使用SELECT INTO进行备份的内容,更多相关文章请关注PHP中文网(www.php.cn)!
ECSHOP仿优购鞋子商城整站源码,程序基于ECSHOP 2.7.3 UFT8版本制作,适合服装,鞋子,家居等商城使用。目前程序未添加广告位,请自行在网站后台进行添加。具体添加方法,请查看SHOPEX5站点的相关教程。 安装方法:1。访问 :域名/install2. 按照程序提示进行安装.3.安装完成后,登陆网站后台.选择数据库管理--数据库备份--数据库还原.,导入之前的数据库。4.后台-模板管









