How to deploy MySQL using Docker and set a password?

To deploy a MySQL container and set a password, you can follow these steps:

  1. Firstly, make sure that Docker is installed and the Docker service is running.
  2. Open the terminal or command prompt and run the following command to pull the MySQL image and create a MySQL container:
  3. Run a MySQL container named “mysql” with the latest version, specifying a root password of your choice, and mapping port 3306 on the host to port 3306 on the container.
  4. This command will create a container named ‘mysql’ and map the default port 3306 of the MySQL service to port 3306 on the host machine. Use the option -e MYSQL_ROOT_PASSWORD=your_password to set the root user password for MySQL, replace ‘your_password’ with the desired password.
  5. Next, you can verify if the MySQL container has been successfully deployed and running by using the following command:
  6. list all running containers
  7. If the status of the MySQL container shows “Up”, it means that the container has been successfully deployed.
  8. Finally, you can connect to the MySQL container using any MySQL client. For example, you can connect to the MySQL container using the following command:
  9. Connect to MySQL server on local host using username “root” and password, specifying the port as 3306.
  10. You can successfully connect to the MySQL container by entering the previously set password.

Note: The password setting in the above steps is just an example, you can replace “your_password” with the password you want to set. Additionally, you can also customize the behavior of the MySQL container by setting other MySQL environment variables according to your needs.

bannerAds