1. 获取mysql镜像
# docker pull mysql/mysql-server:latest
# docker images
2. 创建mysql容器
# docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=你的密码 -d mysql/mysql-server:latest
3. 启动mysql容器
# docker ps -s
# docker start mysql
4. 连接mysql测试
# docker exec -it mysql bash
# mysql -u root -p
mysql> use mysql;
mysql> select host, user from user;
5. 开启远程访问(如有需要)
mysql> use mysql;
mysql> CREATE USER 'root'@'%' IDENTIFIED BY '你的密码';
mysql> GRANT ALL ON *.* TO 'root'@'%';
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密码';
mysql> FLUSH PRIVILEGES;
mysql> DELETE FROM user WHERE host <> '%' AND user = 'root';
参考文献
网友评论