Docker Installation of MySQL
MySQL is the world's most popular open-source database. Known for its reliability, ease of use, and performance, MySQL has become the preferred choice for databases in web applications.
1. Check Available MySQL Versions
Visit the MySQL image repository address: https://hub.docker.com/_/mysql?tab=tags.
You can view other versions of MySQL by sorting with "Sort by," with the default being the latest version mysql:latest.
Additionally, we can use the docker search mysql
command to check available versions:
$ docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relati... 2529 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Crea... 161 [OK]
centurylink/mysql Image containing mysql. Optimized to be li... 45 [OK]
sameersbn/mysql 36 [OK]
google/mysql MySQL server for Google Compute Engine 16 [OK]
appcontainers/mysql Centos/Debian Based Customizable MySQL Con... 8 [OK]
marvambass/mysql MySQL Server based on Ubuntu 14.04 6 [OK]
drupaldocker/mysql MySQL for Drupal 2 [OK]
azukiapp/mysql Docker image to run MySQL by Azuki - http:... 2 [OK]
...
2. Pull the MySQL Image
Here, we pull the official latest version of the image:
$ docker pull mysql:latest
3. Check Local Images
$ docker images
In the image above, we can see that we have installed the latest version (latest) of the mysql image.
4. Run the Container
After installation, we can use the following command to run the mysql container:
$ docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql
Parameter explanations:
-p 3306:3306: Maps the container's 3306 port to the host's 3306 port, allowing external hosts to directly access the MySQL service via
host_ip:3306
.MYSQLROOTPASSWORD=123456: Sets the password for the root user of the MySQL service.
5. Installation Success
Check if the installation was successful using the docker ps
command:
You can access the MySQL service locally using the root user and the password 123456.