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);








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