docker pull mysql:5.7
docker run -p 3306:3306 --name mysql_0912 -v PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
简述:
-p 3306:3306 将容器的3306端口映射到主机的3306端口上
-v PWD/data:/var/lib/mysql 讲主机的当前目录下的data目录挂载到容器的/var/lib/mysql
-e MYSQL_ROOT_PASSWORD=123456 初始化root账号的密码
docker ps -a 获取mysql的容器信息
执行
docker exec -it 容器id /bin/bash
进入myql后 执行
mysql -uroot -p123456
进入交互界面
进行授权
GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON . TO 'root'@'127.0.0.1' IDENTIFIED BY 'root' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON . TO 'root'@'localhost' IDENTIFIED BY 'root' WITH GRANT OPTION;
FLUSH PRIVILEGES;