这篇具有很好参考价值的文章主要介绍了[Docker] 8.2 Docker 部署 MySQL 8.0.17。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。
搜索 MySQL 镜像
docker
官网:https://hub.docker.com/_/mysql
下载 MySQL 镜像
默认最新版本
运行 MySQL 容器
1
2
3
4
5
6
|
docker run -p 3306:3306 --name mysql \
-v /usr/local/docker/mysql/conf:/etc/mysql/conf.d/ \
-v /usr/local/docker/mysql/logs:/var/log/mysql \
-v /usr/local/docker/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql
|
命令参数:
-
-p 3306:3306
:将容器的3306端口映射到主机的3306端口
-
-v /usr/local/docker/mysql/conf:/etc/mysql/conf.d/
:将主机当前目录下的 conf
挂载到容器的 /etc/mysql/conf.d/
-
-v /usr/local/docker/mysql/logs:/var/log/mysql
:将主机当前目录下的 logs
目录挂载到容器的 /var/log/mysql
-
-v /usr/local/docker/mysql/data:/var/lib/mysql
:将主机当前目录下的 data
目录挂载到容器的 /var/lib/mysql
-
-e MYSQL_ROOT_PASSWORD=123456
:初始化 root
用户的密码
-
查看容器是否运行
进入 MySQL 容器
1
|
docker exec -it mysql bash
|
在容器内登陆 MySQL
查看用户信息并赋予访问权限
1
|
select host,user,plugin,authentication_string from mysql.user;
|
结果:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
mysql> select host,user,plugin,authentication_string from mysql.user;
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| host | user | plugin | authentication_string |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| % | root | caching_sha2_password | $A$005$f+WN\N>cQO#;SqoIG3n5hmq/r6LF5EV2/O4lp5VMw3JQXQfz6DzHeqWV0 |
| localhost | mysql.infoschema | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root | caching_sha2_password | $A$005$I T9Cz|
VE\
9AXGgVLqIOitU4MzwycwC/jRXmroU2M.pObTLs9T5tz7 |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
5 rows in set (0.00 sec)
|
备注:
-
host
为 %
表示不限制 ip
-
localhost
表示本机使用
-
plugin
非 mysql_native_password
则需要修改密码
1
2
3
|
ALTER user 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
FLUSH PRIVILEGES;
|
再次查询:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
mysql> select host,user,plugin,authentication_string from mysql.user;
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| host | user | plugin | authentication_string |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| % | root | mysql_native_password | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost | mysql.infoschema | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root | caching_sha2_password | $A$005$I T9Cz|
VE\
9AXGgVLqIOitU4MzwycwC/jRXmroU2M.pObTLs9T5tz7 |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
5 rows in set (0.01 sec)
|
最后退出:文章来源:https://www.toymoban.com/news/detail-843329.html
文章来源地址https://www.toymoban.com/news/detail-843329.html
到了这里,关于[Docker] 8.2 Docker 部署 MySQL 8.0.17的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!