现在有张表为student,我想将这个表里面的数据复制到一个为dust的新表中去。
answer 01:
create table dust select * from student;//用于复制前未创建新表dust的情况下
answer 02:
insert into dust select * from student;//已经创建了新表dust的情况下

现在使用select..into..语句实现以上东东。

MySQL不支持Select Into语句直接备份表结构和数据,一些种方法可以代替, 也有其它方法可以处理,总结如下:
方法1:
MYSQL不支持:
Select * Into new_table_name from old_table_name; 这是sql server中的用法
替代方法:
Create table new_table_name (Select * from old_table_name);

方法2:
1.先备份表结构和数据

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.完成.

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\’;

mysql> load data local infile “d:/gpsdata.txt” into table positiondata fields terminated by \’;\’ (userid,latitude,longitude,altitude,speed,innerid,repo
rttime,status);

LOAD DATA [LOW_PRIORITY CONCURRENT] [LOCAL] INFILE ’file_name.txt’
[REPLACE IGNORE]
INTO TABLE tbl_name
[FIELDS
[TERMINATED BY ’string’]
[[OPTIONALLY] ENCLOSED BY ’char’]
[ESCAPED BY ’char’ ] ]
[LINES
[STARTING BY ’string’]
[TERMINATED BY ’string’] ]
[IGNORE number LINES]
[(col_name_or_user_var,…)]
[SET col_name = eXPr,…)]

fields和lines在前面,(col_name_or_user_var,…)在后面 如果你使用的时候直接把要写的这些属性放在表名后面,这样是不正确的,一定要写到fields和lines的后面!

版权声明:本文为caijiqi190731原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/caijiqi190731/p/11433367.html