您的位置:首页 > 数据库 > MySQL

MySQL表结构复制、表数据迁移以及临时表、视图创建

2015-03-10 11:24 435 查看
1、只拷贝表结构,不拷贝数据

select * into b from a where 1<>1;


 

2、表数据迁移

      表b已经存在:

insert into b (d, e, f) select a, b, c from a;


     表b原先不存在:

create table b (select a, b, c from a);


 

3、创建临时表

      创建临时表的语法很简单,临时表存在内存中,会话结束即消失:

create temporary table a (...);


 

4、创建视图

      视图属于数据库:

create view test.myView as select a, b from a;


 

注:文章转载至  http://www.cnblogs.com/feichexia/archive/2012/12/21/2827837.html

创建新表时,将结果集 插入到新表中

Create table new_table_name (Select * from old_table_name);
select * into new_table_name from old_table_name;

mysql 用户信息的创建及赋予权限

1.创建一个用户,用于远程登陆即数据操作
 create user
4000
 'webanker'@'%' identified by 'webanker'; 
2.赋予该用户一些操作权限,grant all on webanker 说明,赋予了用户操作该数据库下所有的所有操作权限
 grant all on webanker.* to 'webanker'@'%' identified by 'webanker' with grant option; 
注:有需要的话,在创建此用户的同时,应该创建一个相同的本地用户,即 'webanker'@'localhost'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: