Home  >  Article  >  Database  >  How docker deploys mysql to achieve remote connection

How docker deploys mysql to achieve remote connection

王林
王林forward
2023-05-28 21:30:442624browse

1.docker search mysql Check mysql version

How docker deploys mysql to achieve remote connection

##2.docker pull mysql

Select the name with the highest starts to download

3.docker images

View the downloaded image

4. Start the mysql instance

 docker run --name dockermysql -p 3307:3306 -e mysql_root_password=my-secret-pw -d mysql

--name Set an alias for the mysql instance. -p 3307 is the port exposed to the outside world. 3306 is the internal port

-e mysql_root_password Set mysql login password -d Run as a daemon process (run in the background) The last mysql is the image name

5. docker ps - a

View the running

How docker deploys mysql to achieve remote connection##6. docker exec -it dockermysql bash

Enter the container dockermysql is the alias given to the container when running above You can also use id instead

7.docker mysql -u root -p

Then enter the password directly. The password is set at runtime

How docker deploys mysql to achieve remote connectionuse mysql

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

Grant permissions

grant all privileges on *.* 'root'@'%' identified by '123123' with grant option; This is a writing method that is widely circulated on the Internet. In fact, an error will be reported.

9.flush privileges; Refresh privileges

10.Login

How docker deploys mysql to achieve remote connection11.mysql remote connection error:

authentication plugin caching_sha2

mysql 8.0 uses the caching_sha2_password authentication mechanism by default - changed from the original mysql_native_password to caching_sha2_password.

Upgrading from 5.7 to version 8.0 will not change the authentication method of existing users, but new users will use the new caching_sha2_password by default.

The client does not support the new encryption method.

One of the methods is to modify the user's password and encryption method

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

must be assigned to the same user permissions are the same. If it is localhost, the same as above. The same is true for %

mysql8.*’s new feature caching_sha2_password password encryption method

The previous version of mysql password encryption used

mysql_native_password


The default password for newly added users is

caching_sha2_password


If you upgrade based on the previous mysql, the password encryption used by the user must use mysql_native_password


If you use the previous password encryption method, modify the file /etc/my.cnf

Database time zone problem:

Problems with the servertimezone=utc parameter when linking to the database

Just change it to servertimezone=asia/shanghai and it will be ok!

The above is the detailed content of How docker deploys mysql to achieve remote connection. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete