接上一篇:Linux運維必會的100道MySql面試題之(一)
21.刪除test表中的所有數據,並查看
delete from test;
select * from test;
22.刪除表test和mingongge數據庫並查看
drop table test;
show tables;
drop database mingongge;
show databases;
23.不退出數據庫恢復以上刪除的數據
system mysql -uroot -pMgg123.0. </root/mingongge_bak.sql
24.把庫表的GBK字符集修改爲UTF8
alter database mingongge default character set utf8;
alter table test default character set utf8;
25.把id列設置爲主鍵,在Name字段上創建普通索引
alter table test add primary key(id);
create index mggindex on test(name(16));
26.在字段name後插入手機號字段(shouji),類型char(11)
alter table test add shouji char(11);
#默認就是在最後一列後面插入新增列
27.所有字段上插入2條記錄(自行設定數據)
insert into test values('4','23','li','13700000001'),('5','26','zhao','13710000001');
28.在手機字段上對前8個字符創建普通索引
create index SJ on test(shouji(8));
29.查看創建的索引及索引類型等信息
show index from test;
show create table test\G
#下面的命令也可以查看索引類型
show keys from test\G
30.刪除Name,shouji列的索引
drop index SJ on test;
drop index mggindex on test;
31.對Name列前6個字符以及手機列的前8個字符組建聯合索引
create index lianhe on test(name(6),shouji(8));
32.查詢手機號以137開頭的,名字爲zhao的記錄(提前插入)
select * from test where shouji like '137%' and name = 'zhao';
33.查詢上述語句的執行計劃(是否使用聯合索引等)
explain select * from test where name = 'zhao' and shouji like '137%'\G
34.把test表的引擎改成MyISAM
alter table test engine=MyISAM;
35.收回mingongge用戶的select權限
revoke select on mingongge.* from mingongge@localhost;
36.刪除mingongge用戶下數據庫mingongge
drop user migongge@localhost;
drop database mingongge;
37.使用mysqladmin關閉數據庫
mysqladmin -uroot -pMgg123.0. shutdown
lsof -i :3306
38.MySQL密碼丟了,請找回?
mysqld_safe --skip-grant-tables &
#啓動數據庫服務
mysql -uroot -ppassowrd -e "use mysql;update user set passowrd = PASSWORD('newpassword') where user = 'root';flush privileges;"
點擊關注 民工哥技術之路 微信公衆號對話框回覆關鍵字:1024 可以獲取一份最新整理的技術乾貨:包括系統運維、數據庫、redis、MogoDB、電子書、Java基礎課程、Java實戰項目、架構師綜合教程、架構師實戰項目、大數據、Docker容器、ELK Stack、機器學習、BAT面試精講視頻等。