千家信息网

docker中如何安装mysql

发表于:2024-12-02 作者:千家信息网编辑
千家信息网最后更新 2024年12月02日,这篇文章主要介绍docker中如何安装mysql,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!1、docker hub上面查找mysql镜像[root@t-docker tom
千家信息网最后更新 2024年12月02日docker中如何安装mysql

这篇文章主要介绍docker中如何安装mysql,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

1、docker hub上面查找mysql镜像

[root@t-docker tomcatlogs]# docker search mysqlNAME                                                   DESCRIPTION                                     STARS               OFFICIAL            AUTOMATEDmysql                                                  MySQL is a widely used, open-source relation…   6845                [OK]                mariadb                                                MariaDB is a community-developed fork of MyS…   2185                [OK]                mysql/mysql-server                                     Optimized MySQL Server Docker images. Create…   502                                     [OK]percona                                                Percona Server is a fork of the MySQL relati…   365                 [OK]                zabbix/zabbix-server-mysql                             Zabbix Server with MySQL database support       120

2、从docker hub上(或阿里云加速器)拉取mysql镜像到本地

[root@t-docker tomcatlogs]# docker pull mysql:5.65.6: Pulling from library/mysqlbe8881be8156: Already exists c3995dabd1d7: Pulling fs layer 9931fdda3586: Pulling fs layer bb1b6b6eff6a: Pulling fs layer a65f125fa718: Pulling fs layer 62fa8db7a5dc: Pulling fs layer a65f125fa718: Waiting 0f5681d76128: Pull complete 56d3348c5742: Pull complete b93f67de42c4: Pull complete 5adba6c10127: Pull complete Digest: sha256:2e48836690b8416e4890c369aa174fc1f73c125363d94d99cfd08115f4513ec9Status: Downloaded newer image for mysql:5.6
[root@t-docker tomcatlogs]# docker images mysqlREPOSITORY          TAG                 IMAGE ID            CREATED             SIZEmysql               5.6                 7edb93321b06        4 weeks ago         256MB

3、使用mysql镜像创建容器(也叫运行镜像)

[root@t-docker chenzx]# docker run -p 12345:3306 --name mysql -v /volume/mysql/conf:/etc/mysql/conf.d -v /volume/mysql/logs:/logs -v /volume/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6

命令说明:

-p 12345:3306:将主机的12345端口映射到docker容器的3306端口;

--name mysql:运行容器的名字

-v 挂载宿主机上的数据卷到容器里面

-e MYSQL_ROOT_PASSWORD=123456:初始化root的密码

-d mysql:5.6:后台运行mysql5.6

[root@t-docker chenzx]# docker psCONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                              NAMES6dc80df5e339        mysql:5.6           "docker-entrypoint.s…"   About a minute ago   Up About a minute   0.0.0.0:12345->3306/tcp            mysql
[root@t-docker chenzx]# docker exec -it 6dc80df5e339 /bin/bashroot@6dc80df5e339:/# mysql -uroot -p123456Warning: 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 1Server version: 5.6.41 MySQL Community Server (GPL)Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> status ;--------------mysql  Ver 14.14 Distrib 5.6.41, for Linux (x86_64) using  EditLine wrapperConnection id:1Current database:Current user:root@localhostSSL:Not in useCurrent pager:stdoutUsing outfile:''Using delimiter:;Server version:5.6.41 MySQL Community Server (GPL)Protocol version:10Connection:Localhost via UNIX socketServer characterset:latin1Db     characterset:latin1Client characterset:latin1Conn.  characterset:latin1UNIX socket:/var/run/mysqld/mysqld.sockUptime:5 min 10 secThreads: 1  Questions: 5  Slow queries: 0  Opens: 67  Flush tables: 1  Open tables: 60  Queries per second avg: 0.016--------------

4、备份docker容器里面的MySQL

[root@t-docker chenzx]# docker psCONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                              NAMES6dc80df5e339        mysql:5.6           "docker-entrypoint.s…"   16 minutes ago      Up 16 minutes       0.0.0.0:12345->3306/tcp            mysql
[root@t-docker chenzx]# docker exec 6dc80df5e339 sh -c 'exec mysqldump -uroot -p123456 -B mysql' > mysql.sql

以上是"docker中如何安装mysql"这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!

0