📜  docker run mysql (1)

📅  最后修改于: 2023-12-03 14:40:49.652000             🧑  作者: Mango

Docker Run MySQL

Docker is a containerization platform that allows you to package and distribute your applications along with their dependencies, ensuring consistency across different environments. With Docker, you can easily run MySQL, a popular open-source relational database management system.

Step 1: Install Docker

Before you can run MySQL using Docker, you need to install Docker on your system. Please refer to the official Docker documentation for instructions on how to install Docker for your operating system.

Step 2: Pull MySQL Image

Once Docker is installed, you need to pull the MySQL image from the Docker Hub repository. Run the following command to pull the latest MySQL image:

docker pull mysql

This will download the MySQL image to your local system.

Step 3: Run MySQL Container

To run a MySQL container, you need to use the docker run command. Here is an example command to run a MySQL container:

docker run -d --name mysql_container -e MYSQL_ROOT_PASSWORD=your_password -p 3306:3306 mysql

Let's break down the command:

  • -d: Runs the container in the background (detached mode).
  • --name mysql_container: Assigns a name to the container.
  • -e MYSQL_ROOT_PASSWORD=your_password: Sets the root password for the MySQL database.
  • -p 3306:3306: Maps the container's MySQL port (3306) to the host's MySQL port (3306).
  • mysql: Specifies the name of the Docker image to use.
Step 4: Access MySQL

Once the container is running, you can access MySQL using any MySQL client. You can connect to the MySQL server using the following details:

  • Host: localhost
  • Port: 3306
  • Username: root
  • Password: your_password (as specified in the docker run command)
Conclusion

Running MySQL using Docker is a convenient way to set up and manage a MySQL database server. It allows you to isolate your database environment and easily replicate it across different machines. Docker provides a portable and consistent way to run MySQL, making it easier for developers to work with databases.