MySQL的基本操作

来源:互联网 发布:云计算售前面试题 编辑:程序博客网 时间:2024/04/28 11:34

 

1,导入外部的数据格式是.txt

 1> 将其修改为.sql文件
 
 2> 进入数据库
  source /.../...sql
2,创建本地的用户
 grant usage on *.* to
'username'@'localhost' identified by 'password'

3,创建远程用户和密码:
 grant usage on *.* to
'username'@'%' identified by 'password'
 
 将数据库中的表导入到excle中
  执行: odbcad32
  创建DNS可在excle中执行操作
4,删除用户:
 drop user
'username'@'localhost'

5,颁布权限:
 grant create on dbname.* to
'username'@'localhost'
 删除权限
 revoke select on dbname.* from
'username‘@’localhost';

6,创建数据库的帮助命令:
 mysqladmin -help

7,在外部创建MySQL的数据库
  mysqladmin -uroot -proot create db01;

8,删除数据库:
 mysqladmin -uroot -proot --force=ture drop db01;

9,备份数据库
 mysqldump -uroot -proot --database example > ex.sql
 
 还原数据库
 
 source /ex.sql

10,基本操作:
 1> 实现前n项的显示:
  select * from t1 limit 2;
 2>实现第二到第四条的显示:
  select * from t1 limit ,2;
 3>随机选择两项显示:
  select * from t1 by rand() limit 2;
 4>显示表的信息:
  desc t1;
 5>添加表的主键:
  alter table add constraint pk01 primary key (id);
 6>创建主外键的关系:
  create table t2(
   id int references t1(id),-------建立外键
   math int);
 7> 添加表的外键:
  alter table t4 add constraint fk01 foreign key (id) reference t1 (id);
 8>添加惟一性的约束:
  alter table t1 add constraint un1 unique(name);
 9>添加默认的属性:
  alter table t5(
   id int,
   city varchar(30) defalut 'beijng');
 10>创建索引:
  create index in1 on tt1 (id);
  删除索引:
  drop index in1 on tt1;
  创建唯一性索引:
  create unique index in1 on tt1(id);
  alter table t4 add
 11>复制表:
  insert into tt1 select id,name from t1;

 12>显示执行计划:
  explain select * from tt1 where id=5;  
 

原创粉丝点击