Docker install MySQL container

Table of contents

1. View available MySQL versions

2. Pull the MySQL image

3. View the local mirror

4. Run the container

5. The installation is successful

6. External connection mysql


1. View available MySQL versions

Visit the MySQL mirror library address: Docker Hub  .

You can view other versions of MySQL through Sort by, the default is the latest version  mysql:latest  .

You can also find other versions you want in the dropdown list:

In addition, we can also use the docker search mysql command to view available versions:

docker search mysql

2. Pull the MySQL image

Here we pull the official latest version of the image:

docker pull mysql:latest

3. View the local mirror

Use the following command to check if mysql is installed:

docker images

In the picture above you can see that we have installed the latest version (latest) of the mysql image.

4. Run the container

After the installation is complete, we can run the mysql container with the following command:

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

Parameter Description:

  • -p 50001:3306  : Map port 3306 of the container service to port 50001 of the host, and the external host can directly access the MySQL service through the host ip:50001.
  • MYSQL_ROOT_PASSWORD=123456 : Set the password of the MySQL service root user.

5. The installation is successful

Use the docker ps command to check whether the installation is successful:

The MySQL service can be accessed as root and password 123456.

First enter the mysql container:

docker exec -it mysql bash

 

 Enter mysql:

mysql -u root -p

Then press Enter to enter the password

 6. External connection mysql

Use Navicat to connect to the mysql server:

Guess you like

Origin blog.csdn.net/lwpoor123/article/details/127981730