1. 启动
5.7版本
docker pull mysql:5.7.38
docker run --name mysql -p 3306:3306 -v /home/data/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7.38
8.0版本
docker pull mysql:8.0.29
docker run --name mysql -p 3306:3306 -v /home/data/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:8.0.29
2. 修改远程访问
进入容器:
docker exec -it mysql bash
进入mysql
mysql -uroot -p123456 -h127.0.0.1
执行flush privileges:
mysql> flush privileges;
3. 添加其他远程登录用户
mysql> create user 'someuser'@'%' identified by 'password';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to "someuser"@"%" with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)