您好,登錄后才能下訂單哦!
這篇文章主要介紹docker中如何安裝mysql,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
1、docker hub上面查找mysql鏡像
[root@t-docker tomcatlogs]# docker search mysql NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql 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.6 5.6: Pulling from library/mysql be8881be8156: 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:2e48836690b8416e4890c369aa174fc1f73c125363d94d99cfd08115f4513ec9 Status: Downloaded newer image for mysql:5.6
[root@t-docker tomcatlogs]# docker images mysql REPOSITORY TAG IMAGE ID CREATED SIZE mysql 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 ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6dc80df5e339 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/bash root@6dc80df5e339:/# mysql -uroot -p123456 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 1 Server 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 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> status ; -------------- mysql Ver 14.14 Distrib 5.6.41, for Linux (x86_64) using EditLine wrapper Connection id:1 Current database: Current user:root@localhost SSL:Not in use Current pager:stdout Using outfile:'' Using delimiter:; Server version:5.6.41 MySQL Community Server (GPL) Protocol version:10 Connection:Localhost via UNIX socket Server characterset:latin1 Db characterset:latin1 Client characterset:latin1 Conn. characterset:latin1 UNIX socket:/var/run/mysqld/mysqld.sock Uptime:5 min 10 sec Threads: 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 ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6dc80df5e339 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”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。