Successfully access the mysql5.6 database on the local area network through docker under macOS

 

1. Get the mysql image

docker pull mysql:5.6

Note: The reason why mysql5.6 is obtained here is because mysql5.7 may report an error when started in centos7,

2. View the mirror list

docker images

3. Start the mysql image

docker run -itd -P mysql:5.6 bash

where docker run is the command to start the container; i is an interactive operation, t is a terminal, d refers to running in the background,

-P refers to generating a random port locally to map the 3306port of mysql, mysql refers to running the mysql image, and bash refers to creating an interactive shell.

4. View the running docker image

docker ps -a

It can be seen from the figure that the 3306 port of the mysql image is bound to the local 32769 port, so if you want to access the mysql database in docker in the local area network, you need to use the server IP: 32769 to access.

5. Connect to the mysql image

docker exec -it relaxed_hodgkin bash

docker exec is the connection command of the docker image, similar to the ssh command, relaxed_hodgkin is the name of the image, each time the image is started, it must have a name, which can be specified manually or generated by itself. 

After the connection is successful, as shown below, it has entered the docker mysql image

 

6. Check the startup status of mysql, as shown in the figure above, it shows that mysql is not started

service mysql status

7.mysql is not started, you can use the following command to start, as shown in the figure, the startup is successful

service mysql start

8. Enter mysql  to verify that mysql is started successfully

So far, mysql in docker has been started successfully.

 9. How to use root to connect this mysql externally? For security, first you need to set the password of the root account, as follows

update user set authentication_string = password('root') where user = 'root';

The following error will be reported

It is because the database is not selected. To execute the following sentence before the above command, you can change rootthe password to root

use mysql;

10. Since the root execution in mysql is bound localhost, it is necessary to authorize root

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

11. Finally, use SQLyog to test the mysql connection as follows

The connection is successful, indicating that mysql in docker can be used in the local area network.

1. Get the mysql image

docker pull mysql:5.6

Note: The reason why mysql5.6 is obtained here is because mysql5.7 may report an error when started in centos7,

2. View the mirror list

docker images

3. Start the mysql image

docker run -itd -P mysql:5.6 bash

where docker run is the command to start the container; i is an interactive operation, t is a terminal, d refers to running in the background,

-P refers to generating a random port locally to map the 3306port of mysql, mysql refers to running the mysql image, and bash refers to creating an interactive shell.

4. View the running docker image

docker ps -a

It can be seen from the figure that the 3306 port of the mysql image is bound to the local 32769 port, so if you want to access the mysql database in docker in the local area network, you need to use the server IP: 32769 to access.

5. Connect to the mysql image

docker exec -it relaxed_hodgkin bash

docker exec is the connection command of the docker image, similar to the ssh command, relaxed_hodgkin is the name of the image, each time the image is started, it must have a name, which can be specified manually or generated by itself. 

After the connection is successful, as shown below, it has entered the docker mysql image

 

6. Check the startup status of mysql, as shown in the figure above, it shows that mysql is not started

service mysql status

7.mysql is not started, you can use the following command to start, as shown in the figure, the startup is successful

service mysql start

8. Enter mysql  to verify that mysql is started successfully

So far, mysql in docker has been started successfully.

 9. How to use root to connect this mysql externally? For security, first you need to set the password of the root account, as follows

update user set authentication_string = password('root') where user = 'root';

The following error will be reported

It is because the database is not selected. To execute the following sentence before the above command, you can change rootthe password to root

use mysql;

10. Since the root execution in mysql is bound localhost, it is necessary to authorize root

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;

11. Finally, use SQLyog to test the mysql connection as follows

The connection is successful, indicating that mysql in docker can be used in the local area network.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325164091&siteId=291194637