mysql学习总结

mysql常用命令:


创建表A,复制表B的数据结构,(不复制数据)

create table A like B;


复制表B的数据内容到表A中(前提是表A与表B数据结构一致):

insert into A  select   *   from  B;


查看表A的创建语句:

show create table A;


查看表A的数据结构:

desc A;


将sql文件导入到数据库demo:

命令行进入demo数据库 mysql -uroot -p  demo;

输入密码进入后导入   source   /home/zfeig/test.sql;



mysql数据备份与还原

mysqldump -uroot  -h192.168.0.3 news > d:/data/news.sql;//备份数据库

mysqldump -uroot  -h192.168.0.3 news < d:/data/news.sql;//还原数据库



修改mysql的root用户密码:

update mysql.user  set password =password(***) where user="root";

flush privileges;

或者 mysql -u root password "XXXX";


修改mysql的表结构:

alter table A add title varchar(256) not null default ''; //添加字段

alter table A  drop time;//删除字段

alter table A modify id int(10) primary key  auto_increment;//修改字段类型

alter table A change title tiltes varchar(256) not null default '';更改字段名

alter table A rename B;//修改表名


mysql指定用户授权:

// 授权指定用户 所有数据库所有权限

grant all privileges on *.*  to  zfeig@localhost  identified by "123456";

flush privileges;


//授权指定用户某一数据库所有权限

grant all privileges on news.* to [email protected] identified by "123456";

flush privileges;


//授权指定用户某一数据库部分权限

grant select,update,insert  on news.* to [email protected] identified by "123456";



创建索引
alter table news add index id_index(cid);


创建唯一索引
alter table news add unique cid_index(cid);


创建主键索引
alter table news add primary key(id);




查看索引
1、desc news;
2、show index from nerws;




删除索引
alter table news drop indx id_index;




将字段改为主键索引,并设置主键索引


alter table news modify id int(10) not null auto_increment;
alter table news add primary key(id);








發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章