Home > Operation and Maintenance > Docker > 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
Release: 2022-07-22 15:35:18
Original
9545 people have browsed it

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
Copy after login

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;
Copy after login


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;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template