$ docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQLis a widely used, open-source relati...2529[OK]
mysql/mysql-server OptimizedMySQLServerDocker images.Crea...161[OK]
centurylink/mysql Image containing mysql.Optimized to be li...45[OK]
sameersbn/mysql 36[OK]
google/mysql MySQL server forGoogleComputeEngine16[OK]
appcontainers/mysql Centos/DebianBasedCustomizableMySQLCon...8[OK]
marvambass/mysql MySQLServer based on Ubuntu14.046[OK]
drupaldocker/mysql MySQLforDrupal2[OK]
azukiapp/mysql Docker image to run MySQLbyAzuki- http:...2[OK]...
2、拉取 MySQL 镜像
这里我们拉取官方的最新版本的镜像:
$ docker pull mysql:latest
3、查看本地镜像
使用以下命令来查看是否已安装了 mysql:
$ docker images
在上图中可以看到我们已经安装了最新版本(latest)的 mysql 镜像。
4、运行容器
安装完成后,我们可以使用以下命令来运行 mysql 容器:
$ docker run -itd --name mysql-test -p 3306:3306-e MYSQL_ROOT_PASSWORD=123456 mysql
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.
# docker ps
CONTAINER ID IMAGE COMMAND ... PORTS NAMES
4ec4f56455ea c73c7527c03a "docker-entrypoint.sh"...0.0.0.0:3306->3306/tcp mysql
1.docker 安装 mysql 8 版本
# docker 中下载 mysql
docker pull mysql
#启动
docker run --name mysql -p 3306:3306-e MYSQL_ROOT_PASSWORD=Lzslov123!-d mysql
#进入容器
docker exec-it mysql bash
#登录mysql
mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Lzslov123!';#添加远程登录用户
CREATE USER 'liaozesong'@'%' IDENTIFIED WITH mysql_native_password BY 'Lzslov123!';
GRANT ALL PRIVILEGES ON *.* TO 'liaozesong'@'%';