一、簡答題
1.簡述你們公司使用的MySQL版本,并說明具體小版本及GA時間?
5.6.38 5.7.20? 2017-9-13
2.請介紹你熟悉的數(shù)據(jù)庫的種類和代表產(chǎn)品名稱?
NoSQL:Redis Mongodb memcacheRDBMS:Oracle? MySQL? MSSQL PG
3.請簡述MySQL二進制安裝重點步驟?
1.下載,上傳,解壓2. 創(chuàng)建用戶3. 創(chuàng)建相關(guān)目錄并授權(quán)4. 設(shè)置環(huán)境變量5. 初始化數(shù)據(jù)6. 配置文件7. 配置啟動腳本
4.怎么確認(rèn)數(shù)據(jù)庫啟動成功了?
ps-ef|grep mysqldnetstat-lnp|grep3306ss-lnp|grep grep3306mysql 登陸測試
5.簡述你了解的MySQL分支版本情況?
Oracle MySQLMariaDBPercona
6.請簡述mysqld的程序結(jié)構(gòu)(1條SQL語句的執(zhí)行過程)
連接層:提供連接協(xié)議,驗證,專用連接線程SQL層? ? 語法,語義,權(quán)限,解析,優(yōu)化,執(zhí)行,查詢緩存,日志記錄存儲引擎層? ? 相當(dāng)于Linux文件系統(tǒng),例如:InnoDB提供了事務(wù),CSR,熱備,MVCC,行級鎖等
7.請簡述你了解的MySQL的啟動方式
sys-v:mysql.server--->mysqld_safe---->mysqldsystemd:mysqld--defaults-filemysqld_safe mysqld
8.簡述MySQL配置文件默認(rèn)讀取順序
mysqld --help --verbose|grep "my.cnf"
9.mysqld_safe --default-files=/opt/my.cnf & 是什么作用?
自定義配置文件,后臺啟動mysql
10.忘記管理員root的密碼處理過程,請對參數(shù)詳細說明
--skip-grant-tables? 關(guān)閉連接層的驗證功能--skip-netwoking? ? ? 關(guān)閉TCPIP協(xié)議
11.請列舉SQL語句的常用種類
DDLDMLDCLDQL
12.請說明聚集索引和輔助索引的區(qū)別
輔助索引,葉子節(jié)點只存儲,有序的某個列的所有值聚集索引,存儲的是整行數(shù)據(jù)輔助索引一般是配合聚集索引使用,通過輔助所用找到主鍵值,然后通過聚集索引找到數(shù)據(jù)行,減少了回表查詢帶來的隨機IO
13.請簡述以下語句執(zhí)行計劃可能存在的問題
闡述以下語句可能存在的問題,并提出合理解決方案
explain select * from city where countrycode='CHN' order by population;
need-to-insert-img
image.png
1.countrycode沒有走索引,有可能是沒建立索引,或者是索引失效2.出現(xiàn)了filesort文件排序,orderby條件也沒走索引建議:1.如果沒有索引導(dǎo)致,建立聯(lián)合索引(countrycode,population)2.如果是索引失效,刪除索引重建
簡述出現(xiàn)以下結(jié)果的可能原因
need-to-insert-img
image.png
懷疑是 telnum列是字符串類型,可能出現(xiàn)了隱式轉(zhuǎn)換,需要進一步判斷數(shù)據(jù)類型.
14. 請簡述,影響索引樹高度的因素?
數(shù)據(jù)量級:分表分庫分布式索引鍵值太長:前綴索引數(shù)據(jù)類型:charvarchar選擇,enum,選擇合理的數(shù)據(jù)類型
15.請說明數(shù)據(jù)庫啟動失敗的處理思路?
有日志,看日志,沒日志,使用mysqld直接測試啟動
16. MySQL索引的種類都有哪些?
B樹HASHR樹
17. 你了解的MySQL存儲引擎種類有哪些?
InnoDB,MyIAM,CSV
18.InnoDB存儲引擎核心特性
事務(wù),CSR,MVCC,行級鎖,熱備,外鍵
二、操作題
1.創(chuàng)建管理員用戶:oldboy能通過10.0.0.0/24網(wǎng)段任意地址登錄管理MySQL
grant all on *.* to? oldboy@'10.0.0.%'identified by'123';
2.創(chuàng)建應(yīng)用用戶:wordpress能通過172.16.1.0/24網(wǎng)段任意地址登錄操作wordpress庫下的所有表
grantselect,update,delete,insert on wordpress.*to wordpress@'172.16.1.%'identified by'123';
3.請寫出/etc/my.cnf的基礎(chǔ)配置信息
[mysqld]user=mysqlbasedir=/usr/local/mysqldatadir=/data/mysqlsocket=/tmp/mysql.sockserver_id=1port=3306[mysql]socket=/tmp/mysql.sock
4.請寫出使用oldboy用戶遠程登錄MySQL的具體語句
mysql -uoldboy -p -h 10.0.0.51 -P3306
5.查看當(dāng)前數(shù)據(jù)庫的字符集
show charset;
6. 創(chuàng)建GBK字符集的數(shù)據(jù)庫oldboy,并查看已建庫完整語句
create database oldboy charset gbk;show create database oldboy;
7. 請分別介紹 NOT NULL default auto_increament 的作用
NotNULL:非空default:默認(rèn)值auto_increament:自動增長
8. 創(chuàng)建用戶oldboy,使之可以管理數(shù)據(jù)庫oldboy
grant all on oldboy.* to? oldboy@'10.0.0.%'identified by'123';
9. 收回oldboy用戶的drop權(quán)限
revoke drop on oldboy.* from? oldboy@'10.0.0.%';
10. 查看創(chuàng)建的用戶oldboy擁有哪些權(quán)限
show grants for oldboy@'10.0.0.%'
11. 查看表結(jié)構(gòu)及建表的SQL語句
desc stu;show create table stu;
12. 插入一條數(shù)據(jù)“1,oldboy”
insertintot1values(1,'oldboy');
13.再批量插入2行數(shù)據(jù)“2,老男孩”,“3,oldboyedu”
14.查詢名字為oldboy的記錄
select*fromt1wherename='oldboy'
15. 查看數(shù)據(jù)庫中所有引擎的類型
show engines;
16.查看數(shù)據(jù)庫關(guān)于日志的參數(shù)配置
show variables like'%log%';
17.查看handler_read_key當(dāng)前的狀態(tài)信息
show status like'handler_read_key';
18. delete和truncate區(qū)別
delete:邏輯逐條刪除數(shù)據(jù)行trucate:物理刪除表段中的所有數(shù)據(jù)頁
19.test表中,有id、name、shouji列。把id列設(shè)置為主鍵,在Name字段上創(chuàng)建普通索引
create table test(idintnotnullprimary key comment'學(xué)號',namevarchar(64)notnullcomment'姓名',telnumchar(11)notnullcomment'手機號')engineInnoDBCharsetUtf8comment'學(xué)生表';alter table testaddindexidx_name(name);
20. 在手機字段上對前8個字符創(chuàng)建普通索引
alter tableaddindexidx_tel(telnum(8));
21.查看創(chuàng)建的索引及索引類型等信息
desc test;show index from test
22.刪除Name,shouji列的索引
alter table test drop index idx_name ;alter table test drop index idx_tel;
23.對Name列的前6個字符以及手機列的前8個字符組建聯(lián)合索引
alter table testaddindexidx_n_t(name(6),telnum(8));
24. 將shouji列索引替換為唯一鍵索
alter table testaddunique indexidx_tel(telnum);
25.如何查看world數(shù)據(jù)庫下city表中population列的重復(fù)值情況
selectpopulation,count(id)fromworld.citygroupby population havingcount(id)>1order bycount(id)desc;
26. 請列出explain命令中type中多種類型
ALL,INDEX,RANGE,REF,EQ_REF,SYSTEM(const),NULL
27.Select查詢語句加強練習(xí)
統(tǒng)計世界上每個國家的總?cè)丝跀?shù).
selectcountrycode,sum(population)fromcitygroupby countrycode;
統(tǒng)計中國各個省的總?cè)丝跀?shù)量
selectdistrict,sum(population)fromcitywherecountrycode='CHN'groupby district;
統(tǒng)計世界上每個國家的城市數(shù)量
selectcountrycode,count(name)fromcitygroupby countrycode;
統(tǒng)計中國每個省的總?cè)丝跀?shù),將總?cè)丝跀?shù)小于100w進行從高到低排序顯示
selectdistrict,sum(population)fromcitywherecountrycode='CHN'groupby district havingsum(population)<1000000order bysum(ppopulation);
28.生成整個數(shù)據(jù)庫下的所有表的單獨備份語句
SELECTCONCAT("mysqldump -uroot -p123 ",table_schema," ",table_name," >/bak/",table_schema,"_",table_name,".sql")FROMinformation_schema.tables;
29. SQL綜合練習(xí)
1. 查詢平均成績大于60分的同學(xué)的學(xué)號和平均成績;
selectstudent.sname,sc.sno,AVG(sc.score)asggfromstudentjoinsc on sc.sno=student.snogroupby sc.sno having gg>60;
2. 查詢所有同學(xué)的學(xué)號、姓名、選課數(shù)、總成績;
selectstudent.sno,student.sname,count(sc.cno),sum(sc.score)fromstudentjoinsc on sc.sno=student.snogroupby sc.sno;
3. 查詢各科成績最高和最低的分:以如下形式顯示:課程ID,最高分,最低分
selectsc.cno,max(sc.score),min(sc.score)fromstudentjoinsc on sc.sno=student.snogroupby sc.cno;
4. 統(tǒng)計各位老師,所教課程的及格率(case)
count(casewhenisfull(socre,0)>=60then1end)/count(*)groupby 學(xué)科selectteacher.tname,count(casewhenifnull(sc.score,0)>=60then1end)/count(*)*100as'及格率%'fromteacherjoincourseon course.tno=teacher.tnojoinscon sc.cno=course.cnogroupby teacher.tno;
5. 查詢每門課程被選修的學(xué)生數(shù)
selectcourse.cname,count(sc.cno)fromteacherjoincourse on course.tno=teacher.tnojoinsc on sc.cno=course.cnogroupby sc.cno;
6. 查詢出只選修了一門課程的全部學(xué)生的學(xué)號和姓名
selectsc.sno,student.sname,count(sc.cno)fromteacherjoincourse on course.tno=teacher.tnojoinsc on sc.cno=course.cnojoinstudent on student.sno=sc.snogroupby sc.sno havingcount(sc.cno)<2;
7. 查詢選修課程門數(shù)超過1門的學(xué)生信息
selectsc.sno,student.sname,count(sc.cno)fromteacherjoincourse on course.tno=teacher.tnojoinsc on sc.cno=course.cnojoinstudent on student.sno=sc.snogroupby sc.sno havingcount(sc.cno)>1;
8. 統(tǒng)計每門課程:優(yōu)秀(85分以上),良好(70-85),一般(60-70),不及格(小于60)的學(xué)生列表(case)
,group_concat(casewhenisfull(score,0)>=85then sname? end)as'優(yōu)秀',group_concat(casewhenisfull(score,0)between70and85then sname end)as'良好'selectcourse.cname,group_concat(casewhenifnull(sc.score,0)>=85then student.sname end)as'優(yōu)秀',group_concat(casewhenifnull(sc.score,0)between70and85then student.sname end)as'良好',group_concat(casewhenifnull(sc.score,0)between60and70then student.sname end)as'一般',group_concat(casewhenifnull(sc.score,0)<60then student.sname end)as'不及格'fromstudentjoinscon sc.sno=student.snojoincourseon course.cno=sc.cnogroupby course.cno;
9. 查詢平均成績大于85的所有學(xué)生的學(xué)號、姓名和平均成績
selectstudent.sname,sc.sno,AVG(sc.score)asggfromstudentjoinsc on sc.sno=student.snogroupby sc.sno having gg>85;
作者:MySQL_oldguo
鏈接:http://www.itdecent.cn/p/de1646631a98
來源:簡書
著作權(quán)歸作者所有。商業(yè)轉(zhuǎn)載請聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請注明出處。