Solution to failure in connecting to mysql in docker

Solution to failure in connecting to mysql in docker

Scenario: After installing the latest version of MySQL in the Docker container of the virtual machine, the following error appears when using Navicat to connect to MySQL in the virtual machine on the host machine:

2059 : Authentication plugin 'caching_sha2_password' cannot be loaded:

Solution:

1. First, use the docker ps command to check the running container to make sure that the mysql we want to connect to has been started. If it has not been started, use the docker start command to start it (the result in the figure below shows that a mysql has been started)

2. Then run docker exec -it b30062adc08c /bin/bash to enter the mysql container

3. Then enter the mysql -u root -p command, then enter your password, and finally enter the update password statement:

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';

4. Finally, restart MySQL and use navicat to connect successfully.

Supplementary knowledge: Solution to the error of local remote connection to MySQL in Docker (1251)

The error is as follows:

Reason: MySQL 8.0 uses the caching_sha2_password authentication mechanism by default; the client does not support the new encryption method

Solution: Modify the encryption method of the user (root)

1. Enter the mysql container and enter in docker

docker exec -it mysql02 bash

2. Log in to MySQL

mysql -u root -p

As shown in the picture, enter 123456 and press Enter.

3. Set user configuration items

(1) View user information

select host,user,plugin,authentication_string from mysql.user;

(2) Modify the encryption method

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; //123456 is the login password of mysql

(3) Check user information again

select host,user,plugin,authentication_string from mysql.user;

(4) Use Navicate or other database software to connect again, success

(5) Supplement: If you want to exit normally without closing the container, you can exit the container by pressing Ctrl+P+Q

Exit the mysql container: Ctrl+D, press twice

The above solution to the failure to connect to mysql in docker is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Methods for deploying MySQL services in Docker and the pitfalls encountered
  • Detailed explanation of using MySQL database in docker (access in LAN)
  • How to install MySQL 8.0 in Docker
  • Detailed explanation of importing/exporting MySQL data in Docker container
  • Install and run a MySQL instance on Docker
  • A practical record of a docker login mysql error problem

<<:  Mysql optimization tool (recommended)

>>:  Detailed explanation of the difference between JavaScript onclick and click

Recommend

How complicated is the priority of CSS styles?

Last night, I was looking at an interview question...

Flex layout realizes left text overflow and omits right text adaptation

I want to achieve a situation where the width of ...

Why Use DOCTYPE HTML

You know that without it, the browser will use qui...

Summary of common Nginx techniques and examples

1. Priority of multiple servers For example, if e...

Reasons and solutions for MySQL selecting the wrong index

In MySQL, you can specify multiple indexes for a ...

How to use MyCat to implement MySQL master-slave read-write separation in Linux

Table of contents Linux-Use MyCat to implement My...

Solve the problem of mysql's int primary key self-increment

Introduction When we use the MySQL database, we a...

Detailed analysis of MySQL master-slave replication

Preface: In MySQL, the master-slave architecture ...

HTML code that can make IE freeze

We simply need to open any text editor, copy the f...

Use Smart CSS to apply styles based on the user's scroll position

By adding the current scroll offset to the attrib...

Ubuntu20.04 VNC installation and configuration implementation

VNC is a remote desktop protocol. Follow the inst...

Python MySQL database table modification and query

Python connects to MySQL to modify and query data...

Detailed explanation of HTML basics (Part 2)

1. List The list ul container is loaded with a fo...

How to implement input checkbox to expand the click range

XML/HTML CodeCopy content to clipboard < div s...