Docker MySQL installation and remote connections

1. Use the following command to download the docker Mirror MySQL official from the docker Hub. The default tag is the latest.

docker pull mysql

To use the other tag, following the example. "8.0" is the tag. What is a tag? tag is the version number.

docker pull mysql:8.0

 

2. Start the container using the following command.

docker run --name='sky-mysql' -e 'MYSQL_ROOT_PASSWORD=abcd2019' -e MYSQL_ROOT_HOST=% -p 3306:3306 -d mysql:8.0

Note: The above command plus the "-p 3306: 3306", which is the port number 3306 and 3306 put the container port of the host to make a map.

Knock blackboard, draw the point.

The installation of MySQL database and the like, we tend to want remote access to data, but the official MySQL in the docker's help pages do not provide command usage example.

 

In the above command them, "-e MYSQL_ROOT_HOST% =" This option is used to set allow remote access.

Search the web to some posts, provide additional methods, but then tried, this is the most effective method.

 

3. Enter the MySQL container.

sudo docker exec -it sky-mysql bash

 

4. In the MySQL inside the container, log in MySQL DB.

If you do not docker, we installed the MySQL is often the first thing to do is to log on MySQL. But now this step is in the docker container inside operation.

See the following -uroot not? root is the user name; -p represents pressing Enter the password to enter the root user.

If the root user does not remember, please remember this second command option: -e 'MYSQL_ROOT_PASSWORD = abcd2019' .

mysql -uroot -p

 

5. Use the following SQL statements to test to see if our MySQL actually installed. This is the operation in the interior of the container MySQL.

show databases;

 

6. Create a new database. MySQL is still inside the container operations.

create database galaxy;

 

7. Open Navicate Premum, connected to MySQL.

 

 

As shown above, we can see the galaxy database just created, indicating remote connection is successful.

 Reference links:

Docker MySQL remote connections

https://medium.com/@backslash112/start-a-remote-mysql-server-with-docker-quickly-9fdff22d23fd

 

MySQL docker official help page

https://hub.docker.com/_/mysql?tab=description

Guess you like

Origin www.cnblogs.com/majestyking/p/11223515.html