Home  >  Article  >  Operation and Maintenance  >  What should I do if mysql installed with docker cannot be accessed remotely?

What should I do if mysql installed with docker cannot be accessed remotely?

WBOY
WBOYOriginal
2022-07-22 15:35:189520browse

Solution: 1. Log in to the mysql container, and then enter mysql. The syntax is "docker exec -it mysql /bin/bash..."; 2. Use "alter user 'root'@'%' identified with mysql_native_password by '...';" Change the login password; 3. Use navicat to connect to mysql remotely.

What should I do if mysql installed with docker cannot be accessed remotely?

The operating environment of this tutorial: linux7.3 system, docker version 19.03, Dell G3 computer.

What to do if docker installation mysql cannot be accessed remotely

#docker installation mysql

docker pull mysql
docker run --name mysql -p 3307:3306 -e MYSQL_ROOT_PASSWORD=123 -d mysql

At this time, when navicat remotely connects to mysql, the following error will be prompted:

Solution:

1. Log in to the mysql container in the virtual machine, and then enter mysql

docker exec -it mysql /bin/bash
mysql -uroot -p
Enter password: 
mysql> select host,user,plugin,authentication_string from mysql.user;


Note: host is %, which means there is no restriction on ip. Localhost means that the local machine uses a plugin other than mysql_native_password, so you need to change the password.

2. Modify Password

mysql> use mysql;
mysql> alter user 'root'@'%' identified with mysql_native_password by '123';
mysql> flush privileges;
mysql> select host,user,plugin,authentication_string from mysql.user;

3. When the above picture appears, use navicat to remotely connect to mysql again and the success is achieved.

Recommended learning: "docker video tutorial"

The above is the detailed content of What should I do if mysql installed with docker cannot be accessed remotely?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn