现在有张表为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.先备份表结构和数据
#导出命令 -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.完成.

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的后面!

补充一点,A表数据 复制到B表,B表不能有自增ID

如果有自增ID,则不插入自增

insert into B (title) select title from A

mysql中select into 和sql中的select into 对比的更多相关文章

  1. JS中Float类型加减乘除 修复 JQ 操作 radio、checkbox 、select LINQ to SQL:Where、Select/Distinct LINQ to SQL Count/Sum/Min/Max/Avg Join

    JS中Float类型加减乘除 修复   MXS&Vincene  ─╄OvЁ  &0000027─╄OvЁ  MXS&Vincene MXS&Vincene  ─╄Ov ...

  2. java中的泛型和sql中的索引

    sql中的索引 索引:好处查询的速度快,被删除,修改,不会对表产生影响,作用是加速查询: 一种典型的数据库对象 作用:提交数据的查询效率,尤其对一些数据量很大的表 索引是用来为表服务的 索引是orac ...

  3. 英文操作系统中中文乱码(SQL中 NVARCHAR 和 VARCHAR区别)

        varchar在SQL Server中是采用单字节来存储数据的,nvarchar是使用Unico来存储数据的.中文字符存储到SQL Server中会保存为两个字节(一般采用Unico编码),英 ...

  4. 【MYSQL 清空所有的的表中的数据的SQL的生成】

    MYSQL 清空所有的的表中的数据的SQL的生成 select Concat('TRUNCATE TABLE ', TABLE_NAME, ';') from INFORMATION_SCHEMA.T ...

  5. PL/SQL中如何执行DDL、SCL?

    PL/SQL程序中不能直接执行DDL语句.为什么? 假设我们在pl/sql程序中有这样的一条DDL语句—— drop table emp:在第一次解析pl/sql中的“drop table emp;” ...

  6. (转)SQL中的ISNULL函数介绍

    SQL中有多种多样的函数,下面将为您介绍SQL中的ISNULL函数,包括其语法.注释.返回类型等,供您参考,希望对您学习SQL能够有所帮助. ISNULL 使用指定的替换值替换 NULL. 语法ISN ...

  7. SQL中使用关键词创建表或字段

    有时候我们给表或者字段命名时,会无意中选择了一个SQL中的关键字进行命名,然后就报错了: ERROR:  syntax error at or near "limit" MySQL ...

  8. 15 SQL中的安全问题

    SQL中的安全问题     1.SQL注入         demo1:             SELECT * FROM user WHERE username = ? AND password ...

  9. Mybatis在xml配置文件中处理SQL中的大于小于号的方法

    之前在项目中遇到了在SQL中<=不识别的问题,在Navicat中语句正常,在xml中不识别,想起来就记录一下 项目用的是Mybatis,经过网上多次查询,验证,总结方法如下: 一.使用<! ...

随机推荐

  1. uva11630 or hdu2987 Cyclic antimonotonic permutations(构造水题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Cyclic antimonotonic permutations Time Li ...

  2. 微信开发之门店管理{"errcode":40097,"errmsg":"invalid args hint: [xxxxxxx]"}

    最近在做微信端开发,做到门店开发部分,在创建门店的时候遇到40097问题{"errcode":40097,"errmsg":"invalid args ...

  3. SlimDX和WPF的合作应用

    1.首先定义一个DX操作类 using System; using SlimDX; using SlimDX.Direct3D9; using System.Windows.Interop; usin ...

  4. 让PHP程序永远在后台运行

    PHP里有个函数很有用.这是在最近的开发中才逐渐用到的. int ignore_user_abort ( [bool setting] ) 这个函数的作用是指示服务器端在远程客户端关闭连接后是否继续执 ...

  5. Onthink_项目后总结

    ---------------------------------------写代码不孤独__小小代(http://www.cnblogs.com/xiaoxiaodai/) 经过一段时间的沉寂,项目 ...

  6. Flask的session——关于写扩展所学习到的

    这两天端午节.趁着端午节没事干,写了个flask的扩展--flask-RedisSession 在flask中使用该扩展可以让你借助redis数据库轻松获得server-side session. 这 ...

  7. CentOS 6.5 CodeBlocks::wxWidgets安装与配置

    第一步, #yum install  codeblocks codeblocks-contrib codeblocks-devel 第二步,到官方下载源码包,我下的是wxX11的3.0版的. #tar ...

  8. UVA_埃及分数(Hard Version) UVA 12588

    Problem EEg[y]ptian Fractions (HARD version)Given a fraction a/b, write it as a sum of different Egy ...

  9. Pascal's Triangle 解答

    Question Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows  ...

  10. Remove Nth Node From End of List 解答

    Question Given a linked list, remove the nth node from the end of list and return its head. For exam ...