How to run MySQL Docker container on Debian 11.3
- 00:33 lsb_release -a
- 00:47 docker pull mysql/mysql-server:latest
- 01:20 docker images
- 01:39 docker run -p 3307:3307 -d --name=mysqls mysql/mysql-server:latest
- 02:37 docker ps
- 02:49 docker logs mysqls
- 03:24 docker exec -it mysqls bash
- 03:45 MySQL -u root -p
- 04:10 ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
- 04:48 show databases;
- 04:59 create database linuxhelp;
- 05:29 use linuxhelp;
To Run MySQL Docker Container On Debian 11.3
Introduction:
The MySQL database management system is an open-source relational database management system and one of the most popular web server solutions. By storing and structuring data meaningfully, it allows easy access to it. Docker is a platform-as-a-service that supports continuous integration and continuous delivery.
Installation Procedure:
Step 1: Check the OS version by using the below command
root@linuxhelp: ~# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
Step 2: Pull the Docker Image for MySQL by using the below command
root@linuxhelp: ~# docker pull mysql/mysql-server:latest
latest: Pulling from mysql/mysql-server
cdd8b07c6082: Pull complete
c2f1720beca1: Pull complete
39f143a8d6de: Pull complete
118a8285b641: Pull complete
b45cbcaf75c7: Pull complete
d4574372e600: Pull complete
1f565a3cbc52: Pull complete
Digest: sha256:e30a0320f2e3c7b7ee18ab903986ada6eb1ce8e5ef29941b36ec331fae5f10b2
Status: Downloaded newer image for mysql/mysql-server:latest
docker.io/mysql/mysql-server:latest
Step 3: List the docker images by using the below command
root@linuxhelp:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql/mysql-server latest eb5713a2c247 3 weeks ago 428MB
hello-world latest feb5d9fea6a5 11 months ago 13.3kB
Step 4: Deploy and start the MySQL container by using the below command
root@linuxhelp:~# docker run -p 3307:3307 -d --name=mysqls mysql/mysql-server:latest
5286836867a9d62a6d8f4975b48c50c1aee23d348db9319db83fbf0a00054675
Step 5: To check if the Docker MySQL Container is running or not by using the below command
root@linuxhelp:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5286836867a9 mysql/mysql-server: latest "/entrypoint.sh mysq…" 5 seconds ago Up 4 seconds (health: starting) 3306/tcp, 33060-33061/tcp, 0.0.0.0:3307->3307/tcp, :::3307->3307/tcp mysqls
Step 6: Take MySQL root password by using the below command
root@linuxhelp:~# docker logs mysqls
[Entrypoint] MySQL Docker Image 8.0.30-1.2.9-server
[Entrypoint] No password option specified for new database.
[Entrypoint] A random onetime password will be generated.
[Entrypoint] Initializing database
2022-08-23T17:20:02.052268Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2022-08-23T17:20:02.052384Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.30) initializing of server in progress as process 18
2022-08-23T17:20:02.058161Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-08-23T17:20:02.375951Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-08-23T17:20:03.013383Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[Entrypoint] Database initialized
2022-08-23T17:20:07.083331Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2022-08-23T17:20:07.084570Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.30) starting as process 65
2022-08-23T17:20:07.106009Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-08-23T17:20:07.813878Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
[Entrypoint] GENERATED ROOT PASSWORD: UH;=o1Uo9jU%;lz3Gu;Bu5%687_A,I3Z
[Entrypoint] ignoring /docker-entrypoint-initdb.d/*
2022-08-23T17:20:12.271570Z 11 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.30).
2022-08-23T17:20:13.538791Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.30) MySQL Community Server - GPL.
[Entrypoint] Server shut down
[Entrypoint] Setting root user as expired. Password will need to be changed before database can be used.
[Entrypoint] MySQL init process done. Ready for start up.
[Entrypoint] Starting MySQL 8.0.30-1.2.9-server
Step 7: From the container create MySQL by using the below command
root@linuxhelp: ~# docker exec -it mysqls bash
bash-4.4#
Step 8: Login to MySQL by using the below command
bash-4.4# MySQL -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 8.0.30
Copyright (c) 2000, 2022, 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.
Step 9: Next, change the MySQL root server password by using the below command
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.00 sec)
Step 10: show the MySQL databases by using the below command
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
Step 11: create the MySQL databases by using the below command
mysql> create database linuxhelp;
Query OK, 1 row affected (0.01 sec)
mysql> use linuxhelp;
Database changed
Mysql> bye;
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to run MySQL docker container. Your feedback is much welcome.
Comments ( 0 )
No comments available