Docker安裝Mysql服務

時間之弧發表於2018-10-24
  1. 拉取官方映象
# docker pull mysql
# docker inspect mysql | grep ``VERSION``
            "GOSU_VERSION=1.7",
            "MYSQL_VERSION=8.0.11-1debian9"
            "GOSU_VERSION=1.7",
            "MYSQL_VERSION=8.0.11-1debian9"
  1. 執行容器
# docker run -it -d 
  -p 13306:3306 
  --name db_mysql 
  --restart=always 
  -e MYSQL_ROOT_PASSWORD=root 
  -v /opt/docker/mysql/log:/var/log/mysql 
  -v /opt/docker/mysql/data:/var/lib/mysql 
  -v /opt/docker/mysql/conf:/etc/mysql/conf.d 
  mysql 
  1. 檢視容器日誌
`檢視最後200條日誌`
# docker logs --tail=200 db_mysql
`滾動監聽`
# docker logs -f db_mysql
  1. 配置Mysql
# docker exec -it db_mysql sh
# mysql --version
mysql  Ver 8.0.11 for Linux on x86_64 (MySQL Community Server - GPL)
# mysql -uroot -proot
mysql> ALTER USER `root`@`%` IDENTIFIED BY `root` PASSWORD EXPIRE NEVER;
mysql> ALTER USER `root`@`%` IDENTIFIED WITH mysql_native_password BY `root`;
mysql> ALTER USER `root`@`%` identified by `your_passwd`;
mysql> FLUSH PRIVILEGES;
  1. 遠端連線測試
mysql -h SEREVR_IP -P 13306 -uroot -p


相關文章