docker容器下的MySQL远程连接配置方法
docker容器下的MySQL远程连接配置方法
查看docker运行的进程
docker ps -a
显示如下
1
2
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES784d7bfaba29 centos_ssl:v1 "/bin/bash" 26 hours ago Created centos_ssl
b26848309b77 centos:v4 "/bin/bash" 26 hours ago Up About an hour
从上图信息中可以看出,docker容器正在运行一个centos系统。。。
我们进入到这个docker容器的centos系统
docker exec -it b26848309b77 bash
注意这里因为是docker容器运行Centos系统,
如果直接在运行MySQL服务器则可以执行以下命令进入MySQL
docker exec -it mysql bash
mysql是别名,你也可以使用docker容器id进入内部。。。
比如上面的docker exec -it b26848309b77 bash
b26848309b77就是docker容器内运行的id。。。
接下来就可以配置MySQL远程连接了
1
2
3
4
5
6
mysql -uroot -p //登录MySQL服务器
use mysql; //进入MySQL的数据库
select host,user,plugin,authentication_string from mysql.user; //查看用户信息
update user set host='192.168.1.%' where user ='root';
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.%'WITH GRANT OPTION;
只运行来自192.168.1.x
的IP段连接MySQL服务器
允许来自任何网络的连接MySQL服务器,修改为以下代码即可
1
2
3
update user set host='%' where user ='root';
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;
为了方便本地程序使用,我们还需要添加本地MySQL连接的权限
1
2
3
CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY 'yourpasswd';
GRANT EXECUTE, PROCESS, SELECT, SHOW DATABASES, SHOW VIEW, ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TABLESPACE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, INDEX, INSERT, REFERENCES, TRIGGER, UPDATE, CREATE USER, FILE, LOCK TABLES, RELOAD, REPLICATION CLIENT, REPLICATION SLAVE, SHUTDOWN, SUPER ON *.* TO 'root'@'127.0.0.1' WITH GRANT OPTION;
FLUSH PRIVILEGES;
💘 相关文章
- MySQL remote connection configuration method under docker container
- docker重啟容器的多種方法
- ctop一款开源的docker容器监控工具
- docker停止並刪除容器的小問題
- Debian/ubuntu system delete docker virtual bridge
- mysql database connection failed | SQLSTATE[HY000] [2002] Connection refused solution
- MySQL database storage path change
- 个人博客数据库选择,mysql vs sqlite?
- 免費又好用,5 款Docker GUI 工具推薦!
- 收藏:MySQL 數值型函數大全