29/07/2026
mysql

En esta entrada vamos a realizar una instalación de MySQL Server con Docker. Antes de comenzar debes instalar el motor y el cliente Docker en la maquina donde vayas a realizar la instalación. Sino tienes Docker instalado, puedes seguir cualquiera de los muchos tutoriales que existen en la web.

To install correctly, follow the instructions at the following URL:

mysql


If you want to perform an installation by downloading the official image supported by Oracle, you can follow the instructions at the following URL:

mysql

En nuestro caso al tratarse de una base de datos de test, utilizaremos la versión oficial MySQL abierta soportada por la comunidad, es decir la del primer enlace.

En primer lugar, lo primero que tenemos que hacer es descargar la imagen MySQL en nuestro Docker, tal y cómo indica la parte superior de la pantalla de la URL indicada con anterioridad. Si se incorpora el comando «latest» o se deja vació, se bajará la última versión disponible. Si por el contrario, se quisiera una versión específica, es posible especificarlo en el comando. En nuestro caso, bajaremos la última versión disponible.

1. Download the MySQL image MySQL your Docker.

[root@ic-1 ~]# sudo docker pull mysql/mysql-server:latest
Trying to pull repository docker.io/mysql/mysql-server …
latest: Pulling from docker.io/mysql/mysql-server
6a4a3ef82cdc: Pull complete
5518b09b1089: Pull complete
b6b576315b62: Pull complete
349b52643cc3: Pull complete
abe8d2406c31: Pull complete
c7668948e14a: Pull complete
c7e93886e496: Pull complete
Digest: sha256:d6c8301b7834c5b9c2b733b10b7e630f441af7bc917c74dba379f24eeeb6a313
Status: Downloaded newer image for mysql/mysql-server:latest

We can list the Docker images Docker have downloaded to verify that we have our mySQL image mySQL this command:

docker images

REPOSITORY TAG IMAGE ID CREATED SIZE
mysqlmysql latest 1d9c2219ff69 11 months ago 496MB

2. We execute and start our MySQL instance.

To start a new MySQL container, we need to run the following command:

docker –name=container_name –restart on-failure -d image_name:tag

Options:

image_name : Name of the image that we are going to use to execute the container.
- -name : Optional, serves to give a customized name to our container, if omitted, a random name will be generated.
- -restart : Configures the restart policy of the container, a value must be established in case of error. Check documentation to apply this option.

For example, let's launch a new Docker container Docker MySQL using the following command:

With this command, we are starting the MySQL container MySQL "mysqltest" using the latest version of MySQL .

We check that the container is running with the following command:

docker

root@ic-1 ~]# docker
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5b7ba4107799mysql:latest "/entrypoint.sh mysq..." About a minute ago Up About a minute (health: starting) 3306/tcp, 33060-33061/tcp mysql

3.- Recuperamos la password temporal del contenedor mysql

[root@ic-1 ~]# docker logs mysql_test 2> 1 | grep GENERATED
[Entrypoint] GENERATED ROOT PASSWORD: @WK5/k24XE;%/lrGn51v6;q@2Q_KEe5A

4.- Ejecutamos el comando necesario para conectarnos a la base de datos MySQL que está corriendo en el contenedor proporcionando la password temporal obtenida en el paso anterior, de la siguiente manera.

[root@ic-1 ~]# docker exec -it mysql_test mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 471
Server version: 8.0.32
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql>

5.- Una vez dentro de MySQL debemos cambiar la password temporal de root, para ello, lanzamos el comando siguiente:

mysql> ALTER USER USER () identified by 'oracleconraul';
Query OK, 0 rows affected (0.19 sec)

[root@ic-1 ~]# docker exec -it mysql_test mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 519
Server version: 8.0.32 MySQL Community Server – GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> select version();
+———–+
| version() |
+———–+
| 8.0.32 |
+———–+
1 row in set (0.00 sec)

mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| performance_schema |
| sys |
+——————–+
4 rows in set (0.00 sec)

6.- To stop and/or start the docker MySQL, simply do the following:

Stopping the conenedor:

[root@ic-1 ~]# docker mysql
mysql

–Verify that it has stopped correctly by running the command:

docker -a

[root@ic-1 ~]# docker -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5b7ba4107799mysql:latest "/entrypoint.sh mysq..." 4 hours ago Exited ( 0) 3 minutes ago mysql

–Restart the MySQL container MySQL verify that it is running correctly:

[root@ic-1 ~]# docker mysql
mysql

[root@ic-1 ~]# docker -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5b7ba4107799mysql:latest "/entrypoint.sh mysq..." 5 hours ago Up 4 minutes (healthy) 3306/tcp, 33060-33061/tcp mysql

7.- We log back into mysql and start enjoying this database manager.

[root@ic-1 ~]# docker exec -it mysql_test mysql -uroot -p
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 8.0.32 MySQL Community Server – GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement

These are the general steps you need to follow to run MySQL in a docker environment. Currently, this type of deployment is becoming increasingly common not only in development environments, but also in production environments, especially due to its versatility and agility in deployment.

Para una instalación en una máquina o servidor de MySQL, puedes ver esta entrada de mi blog donde se especifica paso a paso cómo instalar una versión de MySQL 8.0 en una máquina o servidor Linux. https://bdconraul.com/instalacion-mysql-8-0-linux/

YouTube
LinkedIn