一、简答题
1.简述你们公司使用的MySQL版本,并说明具体小版本及GA时间?
1 | 5.6.38 |
2.请介绍你熟悉的数据库的种类和代表产品名称?
1 | NoSQL:Redis Mongodb memecache ES |
3.请简述MySQL二进制安装重点步骤?
1 | 1.下载,上传,解压 |
4.怎么确认数据库启动成功了?
1 | ps -ef |grep mysqld |
5.简述你了解的MySQL分支版本情况?
1 | 1.Oracle---->MySQL |
6.请简述mysqld的程序结构(1条SQL语句的执行过程)
1 | 连接层: |
7.请简述你了解的MySQL的启动方式
1 | sys-v:mysql.server--->mysqld_safe---->mysqld |
8.简述MySQL配置文件默认读取顺序
1 | [root@db02 ~]# mysqld --help --verbose|grep "my.cnf" |
9.mysqld_safe --default-files=/opt/my.cnf & 是什么作用?
1 | 自定义配置文件,后台启动mysql. |
10.忘记管理员root的密码处理过程,请对参数详细说明
1 | --skip-grant-tables 关闭连接层的验证功能 |
11.请列举SQL语句的常用种类
1 | DDL 数据定义语言 |
12.请说明聚集索引和辅助索引的区别
1 | 辅助索引,叶子节点只存储,有序的某个列的所有值 |
13.请简述以下语句执行计划可能存在的问题
阐述以下语句可能存在的问题,并提出合理解决方案
explain select * from city where countrycode='CHN' order by population;
image
1 | 1. countrycode没有走索引,有可能是没建立索引,或者是索引失效。 |
简述出现以下结果的可能原因
image
1 | 怀疑是 telnum列是字符串类型,可能出现了隐式转换,需要进一步判断数据类型. |
14. 请简述,影响索引树高度的因素?
1 | 1.数据量级:分表分库分布式 |
15.请说明数据库启动失败的处理思路?
1 | 有日志,看日志,没日志,使用mysqld直接测试启动,看控制台打印的错误日志。 |
16. MySQL索引的种类都有哪些?
1 | 1.B树 |
17. 你了解的MySQL存储引擎种类有哪些?
1 | InnoDB,MyIAM,CSV,MEMORY,MERGE,EXAMPLE,ARCHIVE,BLACKHOLE,FEDERATED。 |
18.InnoDB存储引擎核心特性
1 | 支持事务,CSR,MVCC,行级锁,热备,外键等。 |
二、操作题
1.创建管理员用户:zhangwb能通过10.0.0.0/24网段任意地址登录管理MySQL。
1 | grant all on *.* to zhangwb@'10.0.0.%' identified by '123456'; |
2.创建应用用户:wordpress能通过172.16.1.0/24网段任意地址登录操作wordpress库下的所有表。
1 | grant select,update,delete,insert on wordpress.* to wordpress@'172.16.1.%' identified by '123456'; |
3.请写出/etc/my.cnf的基础配置信息
1 | [mysqld] |
4.请写出使用zhangwb用户远程登录MySQL的具体语句
1 | mysql -uzhangwb -p -h 10.0.0.51 -P3306 |
5.查看当前数据库的字符集
1 | show charset; |
6. 创建GBK字符集的数据库zhangwb,并查看已建库完整语句
1 | create database zhangwb charset gbk engine innodb; |
7. 请分别介绍 NOT NULL default auto_increament 的作用
1 | Not NULL :非空 |
8. 创建用户zhangwb,使之可以管理数据库zhangwb
1 | grant all on zhangwb.* to zhangwb@'10.0.0.%' identified by '123456'; |
9. 收回zhangwb用户的drop权限
1 | revoke drop on zhangwb.* from zhangwb@'10.0.0.%'; |
10. 查看创建的用户zhangwb拥有哪些权限
1 | show grants for zhangwb@'10.0.0.%'; |
11. 查看表结构及建表的SQL语句
1 | desc stu; |
12. 插入一条数据“1,zhangwb”
1 | insert into t1 values(1,'zhangwb'); |
13.再批量插入2行数据“2,zhangwb1”,“3,zhangwb2”
1 | insert into t1 values(2,'zhangwb1'),(3,'zhangwb2'); |
14.查询名字为zhangwb的记录
1 | select * from t1 where name='zhangwb'; |
15. 查看数据库中所有引擎的类型
1 | show engines; |
16.查看数据库关于日志的参数配置
1 | show variables like '%log%'; |
17.查看handler_read_key当前的状态信息
1 | show status like 'handler_read_key'; |
18. delete和truncate区别
1 | delete :逻辑逐条删除数据行 |
19.test表中,有id、name、shouji列。把id列设置为主键,在Name字段上创建普通索引
1 | create table test ( |
20. 在手机字段上对前8个字符创建普通索引
1 | alter table add index idx_tel(telnum(8)); |
21.查看创建的索引及索引类型等信息
1 | desc test; |
22.删除Name,shouji列的索引
1 | alter table test drop index idx_name ; |
23.对Name列的前6个字符以及手机列的前8个字符组建联合索引
1 | alter table test add index idx_n_t(name(6),telnum(8)); |
24. 将shouji列索引替换为唯一键索
1 | alter table test add unique index idx_tel(telnum); |
25.如何查看world数据库下city表中population列的重复值情况
1 | select population,count(id) from world.city group by population having count(id)>1 order by count(id) desc ; |
26. 请列出explain命令中type中多种类型
1 | ALL,INDEX,RANGE,REF,EQ_REF,SYSTEM(const),NULL。 |
27.Select查询语句加强练习
统计世界上每个国家的总人口数.
1 | select code,sum(population) from country group by code; |
统计中国各个省的总人口数量
1 | select district,sum(population) from city where countrycode='CHN' group by district; |
统计世界上每个国家的城市数量
1 | select t.name,t.code,count(c.id) from city as c join country t on c.countrycode=t.code group by t.code; |
统计中国每个省的总人口数,将总人口数小于100w进行从高到低排序显示
1 | select district,sum(population) as total from city where countrycode='CHN' group by district having sum(population)<1000000 order by sum(population) desc; |
28.生成整个数据库下的所有表的单独备份语句
1 | SELECT CONCAT("mysqldump -uroot -p123 ",table_schema," ",table_name," >/tmp/",table_schema,"_",table_name,".sql") |
29. SQL综合练习
1. 查询平均成绩大于60分的同学的学号和平均成绩;
1 | select s.s_no,avg(c.s_core) from student as s join score as c on s.s_no=c.s_no group by s.s_no having avg(c.s_core)>60; |
2. 查询所有同学的学号、姓名、选课数、总成绩;
1 | select s.s_no,s.s_name,c.c_name,sum(o.s_core) from student s join score o on s.s_no=o.s_no join course c on o.c_no=c.c_no group by s.s_no,c.c_no; |
3. 查询各科成绩最高和最低的分:以如下形式显示:课程ID,最高分,最低分
1 | select c.c_no,c.c_name,max(o.s_core) max,min(o.s_core) min from score o join course c on o.c_no=c.c_no group by c.c_no; |
4. 统计各位老师,所教课程的及格率(case)
1 | count(case when isfull(socre,0)>=60 then 1 end)/count(*) |
1 | 方法一、 |
5. 查询每门课程被选修的学生数
1 | select c.c_name,count(t.s_no) from student t join score e on t.s_no=e.s_no join course c on e.c_no=c.c_no group by c.c_no; |
6. 查询出只选修了一门课程的全部学生的学号和姓名
1 | select t.s_no,t.s_name,count(c.c_no) from student t join score e on t.s_no=e.s_no join course c on e.c_no=c.c_no group by t.s_no having count(c.c_no)=1; |
7. 查询选修课程门数超过1门的学生信息
1 | select t.s_no,t.s_name,count(c.c_no) from student t join score e on t.s_no=e.s_no join course c on e.c_no=c.c_no group by t.s_no having count(c.c_no)>1; |
8. 统计每门课程:优秀(85分以上),良好(70-85),一般(60-70),不及格(小于60)的学生列表(case)
1 | ,group_concat(case when isfull(score ,0) >=85 then sname end) as '优秀' |
1 | 方法一、 |
9. 查询平均成绩大于85的所有学生的学号、姓名和平均成绩
1 | select t.s_no,t.s_name,avg(e.s_core) from student t join score e on t.s_no=e.s_no group by t.s_no having avg(e.s_core)>85; |