Docker安装MySQL8.0

System: CentOS7
Docker Version: 20.10.16
Docker API Version: 1.41

Docker安装MySQL8.0, 设置远程访问, 并挂载数据到本地

1. 拉取镜像

docker pull mysql 

在这里插入图片描述

2. 创建并运行容器

 docker run --name [mysql-name] -v [/app/mysql/data]:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=[password] -p [3308]:3306 -d mysql --character-set-server=utf8mb4         docker run --name xmysql -v /app/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=mysql.admin -p 3308:3306 -d mysql --character-set-server=utf8mb4 

3. 设置允许远程连接

打开容器交互模式(容器名称或者ID根据实际情况填写)

docker exec -it xmysql bash 

登录MySQL

mysql -u root -p 

添加远程登录用户(用户名密码可自定义)

CREATE USER 'admin'@'%' IDENTIFIED WITH mysql_native_password BY 'password'; 

给新建用户赋予权限

GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%'; 

刷新

flush privileges; 

4. 连接可视化客户端

在这里插入图片描述

原文链接:https://blog.csdn.net/VXadmin/article/details/128252911?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168994674516800182116245%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=168994674516800182116245&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-5-128252911-null-null.268%5Ev1%5Ekoosearch&utm_term=docker%E3%80%81wordpress%E3%80%81wordpress%E5%BB%BA%E7%AB%99%E3%80%81wordpress%E4%B8%BB%E9%A2%98%E3%80%81%E5%AE%B9%E5%99%A8%E9%95%9C%E5%83%8F%E3%80%81

© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享