How to deploy MySQL using Docker and set a password?
To deploy a MySQL container and set a password, you can follow these steps:
- Firstly, make sure that Docker is installed and the Docker service is running.
- Open the terminal or command prompt and run the following command to pull the MySQL image and create a MySQL container:
- 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.
- 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.
- Next, you can verify if the MySQL container has been successfully deployed and running by using the following command:
- list all running containers
- If the status of the MySQL container shows “Up”, it means that the container has been successfully deployed.
- 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:
- Connect to MySQL server on local host using username “root” and password, specifying the port as 3306.
- 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.