Docker installs MySql and uses external client links

This blog mainly records the installation of mysql in centos7, and the use of external client links after the installation is complete.

1. Check whether the docker environment is normal

Use on the command line docker search mysql:

If you can find out that the docker installation is no problem, then start the next step

Second, download the mysql mirror

Pull the mysql image (default is the latest version)

docker pull mysql

If you need to specify the version number, use:

docker pull mysql:版本号

docker official website: https://hub.docker.com/

You can see some version numbers of mysql from the official website tag

Three, check whether the Mysql image is downloaded successfully

View all mirrors

docker images

Fourth, create a Mysql container

docker run --name mysql01 -p 3306:3306  -e MYSQL_ROOT_PASSWORD=root -d mysql

-p 3306:3306: Map the 3306 port of the host to the 3306 port of the mysql container, and the mysql container can be accessed from the outside through the host ip+3306.

After execution, use docker ps to view the running container:

Enter the mysql container:

$ docker exec -it mysql01 bash

Enter the account and password to log in to mysql:mysql -uroot -proot

#Exit mysql

exit

#Exit the mysql container

exit

In this case, the mysql container can run

Five, test external links

Connecting tools such as sqlyog or Navicat cannot be successfully connected externally! ! !

During this process, mine reported a 1251 error. It was also successfully resolved.

Six, solve the customer service end link mysql report 1251

Enter mysql again
1. Enter the container:

[root@localhost ~]# docker exec -it mysql01 bash

2. Enter mysql:

root@2288abcb04f3:/# mysql -uroot -proot

3. Authorize the remote connection:

mysql> GRANT ALL ON *.* TO 'root'@'%';

4. Encryption rules for changing the password:

mysql> ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;

5. Change root's password:

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

6. Refresh permissions:

mysql> flush privileges;

7. Use the client to test;

Guess you like

Origin blog.csdn.net/weixin_43888891/article/details/113577006