一 安装mysql
----- 由于mysql8.0 登录十分麻烦 现安装数据库为mysql5.0
- 拉取镜像
docker pull hub.c.163.com/library/mysql:5.7
- 启动mysql服务
docker run --name mysql -v /home/mysql/datadir:/var/lib/mysql -v /home/mysql/conf.d:/etc/mysql/conf.d --privileged=true -e MYSQL_ROOT_PASSWORD=123456 -d -i -p 3306:3306 hub.c.163.com/library/mysql:5.7
二 进入mysql容器内部
- sudo docker exec -it f08f5f13eaeb /bin/bash
- 登录mysql mysql -uroot -p
- 选择数据库
use mybatic;
- 在数据库中新建表
create table z( a int not null, b int not null, c int not null,unique key(a))
- 向表中插入数据
insert into z select 1,2,3
- 查询表数据
select * from z;
- 查询表索引
SHOW INDEX FROM z
![image.png](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/e58d16c0dc8641828cbec9bd00c8c505~tplv-k3u1fbpfcp-watermark.image)
- 创建索引
唯一索引
ALTER TABLE z ADD KEY (a) - 设置事务为手动提交
set autocommit = 0;
- 查看执行计划
EXPLAIN SELECT * FROM z WHERE a = '1'
![image.png](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/9d2935218ee94a68909caa8cfcc9fda9~tplv-k3u1fbpfcp-watermark.image)