文章來源:http://www.javashuo.com/article/p-aldsrcxv-bg.html html
1.首先安裝dockerjava
參照一下網址安裝dockermysql
docker:安裝 http://www.javashuo.com/article/p-vaxwojtw-dy.htmlsql
參照安裝一個mysqldocker
docker:安裝mysql http://www.javashuo.com/article/p-zepbfowq-bb.htmlbash
2.建立文件tcp
# mkdir /data # mkdir /data/mysql # mkdir /data/mysql/data5.6 # mkdir /data/mysql/data5.7 # mkdir /data/mysql/data8.0
3.添加鏡像測試
# docker pull mysql:5.6 # docker pull mysql:5.7 # docker pull mysql:8.0
4.啓動鏡像spa
# docker run -d -e MYSQL_ROOT_PASSWORD=123456 --name mysql5.6 --restart always -v /data/mysql/data5.6:/var/lib/mysql -p 3306:3306 mysql:5.6 # docker run -d -e MYSQL_ROOT_PASSWORD=123456 --name mysql5.7 --restart always -v /data/mysql/data5.7:/var/lib/mysql -p 3307:3306 mysql:5.7 # docker run -d -e MYSQL_ROOT_PASSWORD=123456 --name mysql8.0 --restart always -v /data/mysql/data8.0:/var/lib/mysql -p 3308:3306 mysql:8.0
5.打開端口rest
//開啓防火牆 # systemctl start firewalld //開啓3306端口 # firewall-cmd --zone=public --add-port=3306/tcp --permanent //開啓3307端口 # firewall-cmd --zone=public --add-port=3307/tcp --permanent //開啓3308端口 # firewall-cmd --zone=public --add-port=3308/tcp --permanent //重啓防火牆 # systemctl restart firewalld.service
6.本地鏈接測試
7.若是mysql是 8 版本以上應該會出一下錯誤
鏈接Docker啓動的mysql出現:ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded: ÕÒ²»µ½Ö¸¶¨µÄÄ£¿é¡£
解決方案
1.進入mysql容器
docker exec -it mysql /bin/bash
2.進入mysql
mysql -uroot -p123456
3.修改密碼
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';