目录
1. 安装
2. 测试
1. 安装
搜索镜像:
docker search mysql
拉取镜像:
docker pull mysql
创建容器:
docker run --name webj2eedev-mysql \
-v /data/webj2eedev-mysql:/var/lib/mysql \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=webj2eedev@2022 \
-d mysql
进入容器:
docker exec -it webj2eedev-mysql /bin/bash
登录MySQL:
mysql -uroot -pwebj2eedev@2022
切换数据库:
use mysql;
授权:
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'dareway@2022';
刷新权限:
flush privileges;
2. 测试
使用 DBEaver 连接测试一波:
3. 凑个字数
When you start the mysql image, you can adjust the configuration of the MySQL instance by passing one or more environment variables on the docker run command line. Do note that none of the variables below will have any effect if you start the container with a data directory that already contains a database: any pre-existing database will always be left untouched on container startup.
MYSQL_ROOT_PASSWORD
This variable is mandatory and specifies the password that will be set for the MySQL root superuser account. In the above example, it was set to my-secret-pw.
MYSQL_USER, MYSQL_PASSWORD
These variables are optional, used in conjunction to create a new user and to set that user's password. This user will be granted superuser permissions (see above) for the database specified by the MYSQL_DATABASE variable. Both variables are required for a user to be created.
MYSQL_ALLOW_EMPTY_PASSWORD
This is an optional variable. Set to a non-empty value, like yes, to allow the container to be started with a blank password for the root user. NOTE: Setting this variable to yes is not recommended unless you really know what you are doing, since this will leave your MySQL instance completely unprotected, allowing anyone to gain complete superuser access.
参考:
MySQL: https://dev.mysql.com/doc/ DockerHub: https://hub.docker.com/_/mysql