admin avatar

MySQL remote connection configuration method under docker container

🕞 by admin





MySQL remote connection configuration method under docker container

View the processes running by docker

docker ps -a

Show as below

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

As can be seen from the information above, the docker container is running a centos system. . .

We enter the centos system of this docker container

docker exec -it b26848309b77 bash

Note that because it is a docker container running the Centos system,

If you are directly running the MySQL server, you can execute the following command to enter MySQL

docker exec -it mysql bash

mysql is an alias, you can also use docker container id to enter inside. . .

For example, the above docker exec -it b26848309b77 bash

b26848309b77 is the id running in the docker container. . .

Next, you can configure MySQL remote connectionAs can be seen from the information above, the docker container is running a centos system. . .

We enter the centos system of this docker container

docker exec -it b26848309b77 bash

Note that because it is a docker container running the Centos system,

If you are directly running the MySQL server, you can execute the following command to enter MySQL

docker exec -it mysql bash

mysql is an alias, you can also use docker container id to enter inside. . .

For example, the above docker exec -it b26848309b77 bash

b26848309b77 is the id running in the docker container. . .

Next, you can configure MySQL remote connection

1
2
3
4
5
6
mysql -uroot -p //login mysql server
use mysql;  // use mysql data
select host,user,plugin,authentication_string from mysql.user;  //view user info
update user set host='192.168.1.%' where user ='root';
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.%'WITH GRANT OPTION;

Only run the IP segment from 192.168.1.x to connect to the MySQL server

Allow connection to MySQL server from any network, modify to the following code

1
2
3
update user set host='%' where user ='root';
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;

In order to facilitate the use of local programs, we also need to add local MySQL connection permissions

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;





💘 相关文章


📝 有偿服务

• 服务器合租380/年
• 服务器配置:2.4G,6核12线程
• nvme raid 1硬盘
• 不提供服务器自主面板
• 适合稳定的个人博客
• 提供备份服务,备份空间自备
• 只提供ipv6地址,搭配cloudflare使用
• 提供想要安装的程序和域名
• 博客必须是和谐健康的
• 博客不能是视频和图片站
• 提供以下付费服务
• 建站,FTP,备份,Linux,Wordpress等建站问题咨询管理
• 加微信:344452500(不闲聊,直接说事)

写一条评论

Based on Golang + fastHTTP + sdb | go1.16.8 Processed in 1ms