Perfect solution to the problem that Navicat cannot connect after installing mysql in docker

Perfect solution to the problem that Navicat cannot connect after installing mysql in docker

1. Docker pulls the image

docker pull mysql (pull the latest version by default)

2. Run mysql

docker run -p 3308:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql

Container name: mysql Password: 123456

3. Check whether it is running

docker ps -a

4. View the startup log

docker logs mysql

mysql is the name of the container that was just started. Confirm that mysql is started normally.

5. Errors

When I used Navicat to link, I found the following error

We need the following processing

1. Enter the mysql client

docker exec -it c6c8e8e7940f /bin/bash

Where c6c8e8e7940f is the name of my mysql container

----Equivalent command docker exec -it mysql /bin/bash

mysql -u root -p123456

123456 is the login password of mysql, which is set when docker run

2. View user information

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

3. Reset your password

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'newpassword'

newpassword is the new password

I set the password to 'mysql'

4. Reconnect using Navicat

Appendix: It may also be a firewall problem

sudo firewall-cmd --add-port=3306/tcp (open port 3306)

or

sudo systemctl stop firewalld (turn off the firewall)

Supplement: Install MySQL 8 in Docker and configure remote connection

Step 1: Download the mysql image

docker pull mysql

The default is to download the latest stable version

Step 2: Start the mysql image

docker run --name dockermysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=mysqlpassword -d mysql

1. --name is the alias of the image

2. -p maps 3306 to 3306 (docker is a virtual machine with its own port)

3. -e MYSQL_ROOT_PASSWORD=mysqlpassword Set the MySQL server password (needed later, be sure to remember)

4. -d backend startup

5. The image name to be started (can be replaced by id)

Step 3: Query the boot image

docker ps

as follows:

Step 4: Enter the container

docker exec -it dockermysql bash

dockermysql is the name of the image, which can be replaced by id

Step 5: Log in to MySQL

mysql -u root -p

Then enter the password set above

Step 6: Set up remote access

Switch database (this should be the default, you don't need to switch, just switch it for safety)

use mysql;

Change remote link authorization

grant all privileges on *.* to 'root'@'%';

Step 7: Navicat reports error 2059 when connecting

The error is caused by encryption method problem

Check:

select Host,User,plugin from user;

The results before modification are as follows:

Execute the modification command:

alter user 'root'@'%' identified with mysql_native_password by 'yourPassword';

Change to your mysql password

The result after successful modification is as follows:

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me.

You may also be interested in:
  • Solve the problem that Navicat cannot connect to the MySQL server in the Centos system in VMware
  • About the problem of Navicat connecting to MySql database slowly
  • Navicat for MySQL 15 Registration and Activation Detailed Tutorial
  • How to remotely connect to MySQL database with Navicat Premium
  • Solve the problem of error 10038 when connecting to MySQL remotely in Navicat
  • Navicat for MySQL 11 Registration Code\Activation Code Summary
  • Detailed explanation of Navicat's slow remote connection to MySQL
  • Navicat Premium operates MySQL database (executes sql statements)
  • Common errors and solutions for connecting Navicat to virtual machine MySQL
  • When Navicat Premium connects to the database, the error message appears: 2003 Can't connect to MySQL server on''localhost''(10061)
  • Detailed explanation of how to create MySql scheduled tasks in navicat
  • Solution to the problem that Navicat cannot remotely connect to MySql server
  • How to use Navicat to operate MySQL

<<:  How to create a Django project + connect to MySQL

>>:  img usemap attribute China map link

Recommend

Vue Element-ui form validation rule implementation

Table of contents 1. Introduction 2. Entry mode o...

How to modify the user and group of a file in Linux

In Linux, when a file is created, the owner of th...

Do you know how to optimize loading web fonts?

Just as the title! The commonly used font-family l...

VMware Workstation Pro 16 License Key with Usage Tutorial

VMware Workstation is a powerful desktop virtual ...

MySQL uninstall and install graphic tutorial under Linux

This is my first time writing a blog. I have been...

How to install binary MySQL on Linux and crack MySQL password

1. Make sure the system has the required libaio s...

Personal opinion: Talk about design

<br />Choose the most practical one to talk ...

Detailed steps for creating a Vue scaffolding project

vue scaffolding -> vue.cli Quickly create a la...

A brief analysis of the game kimono memo problem

Today, after the game was restarted, I found that...

How to configure Nginx to support ipv6 under Linux system

1. Check whether the existing nginx supports ipv6...

Mysql timeline data to obtain the first three data of the same day

Create table data CREATE TABLE `praise_info` ( `i...

Share a Markdown editor based on Ace

I think editors are divided into two categories, ...

Vue.js framework implements shopping cart function

This article shares the specific code of Vue.js f...

Solution to the garbled problem of web pages when the encoding is set to utf-8

Recently, when I was writing web pages with PHP, I...