docker安装MySQL
# 查看MySQL的版本
地址 : https://hub.docker.com/_/mysql/tags (opens new window)
# docker安装MySQL
# 拉取MySQL 最新版本
docker pull mysql:latest
# 安装 并指定密码
docker run -itd --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
1
2
3
4
5
6
2
3
4
5
6
# 进入容器登录MySQL
# 进入容器
docker exec -it mysql /bin/bash
# 登录 回车,然后输入密码 123456
mysql -uroot -p
1
2
3
4
5
6
2
3
4
5
6
# 授权远程登录
# 进入MySQL这个数据库
uses mysql
# 查看用户信息
select host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host | user | authentication_string | plugin |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| % | root | $A$005$XX<pq.t\^lfIoEqzS9NZ5YNAhAqYUI89UM02y93So3Q5TsIY.LBTN7RXL0C | caching_sha2_password |
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
# 看到有 % 的root的用户,这个就可以远程访问的,授权数据给它即可
GRANT ALL ON *.* TO 'root'@'%';
# 显示 Query OK, 0 rows affected (0.00 sec)
flush privileges;
# 显示 Query OK, 0 rows affected (0.01 sec)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
上次更新: 2024/02/21, 11:34:46