MySQL select into和SQL select into

一.MySQL不支持Select Into语句直接备份表结构和数据,由于工作中的需要在网上找到一种方法可以代替, 也有其它方法可以处理,总结如下:

方法1:
MYSQL不支持:
Select * Into new_table_name from old_table_name;
替代方法:
Create table new_table_name (Select * from old_table_name);

方法2:
1.先备份表结构和数据
#导出命令 -u用户名 -p密码 -h主机IP地址 数据库名 表名1   > 导出文件.sql
mysqldump -uroot -proot -h192.168.0.88 ok_db oktable2 > ok_db.sql

2.修改备份表的名字
3.登录MySQL
4.选择数据库
5.执行: Source 备份表的路径 如:Source d:\ok_db.sql 回车即可。
6.完成.

二. SQLServer支持 Select into语句
1.备份表直接执行如下就可以了。
Select * Into new_table_name from old_table_name;

三. MySQL Select into   outfile用于导出指定的查询数据到文件如下:

1.导出表中所有数据到C盘根目录outfile.txt中如下:
Select * into   outfile 'c:\\outfile.txt' from test;

2.导出表中指定查询条件2005-06-08号的数据到C盘根目录outfile1.txt中如下:
Select * into   outfile 'c:\\outfile.txt' from test where beginDate='2008-06-08';

猜你喜欢

转载自jsx112.iteye.com/blog/1341360