参考链接:https://www.runoob.com/docker/docker-install-mysql.html
查看可用的 MySQL 版本 docker search mysql 拉取 MySQL 镜像 docker pull mysql:latest查看本地镜像
运行容器
docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql # 注意,这里的mysql-test建议改为mysql,方便以后使用。参数说明:
-p 3306:3306 :映射容器服务的 3306 端口到宿主机的 3306 端口,外部主机可以直接通过 宿主机ip:3306 访问到 MySQL 的服务。
MYSQL_ROOT_PASSWORD=123456:设置 MySQL 服务 root 用户的密码。
查看是否安装成功: docker ps最新官方MySQL(5.7.19)的docker镜像在创建时映射的配置文件目录有所不同,在此记录并分享给大家:
官方原文:
The MySQL startup configuration is specified in the file /etc/mysql/my.cnf, and that file in turn includes any files found in the /etc/mysql/conf.d directory that end with .cnf. Settings in files in this directory will augment and/or override settings in /etc/mysql/my.cnf. If you want to use a customized MySQL configuration, you can create your alternative configuration file in a directory on the host machine and then mount that directory location as /etc/mysql/conf.d inside the mysql container.
大概意思是说:
MySQL(5.7.19)的默认配置文件是 /etc/mysql/my.cnf 文件。如果想要自定义配置,建议向 /etc/mysql/conf.d 目录中创建 .cnf 文件。新建的文件可以任意起名,只要保证后缀名是 cnf 即可。新建的文件中的配置项可以覆盖 /etc/mysql/my.cnf 中的配置项。
在阿里云控制台添加防火墙规则,打开3306端口(重要!!!在阿里云服务器中安装什么东西的时候,开了端口映射就要记得在控制台中添加防火墙规则,打开对应的端口。)(之前就是因为没打开端口,报错,找原因找的人有一万句mmp 想说,wc )
再使用Navicat连接,就可以成功!
创作不易,喜欢的话加个关注点个赞,谢谢谢谢谢谢!