在 docker 下部署 mysql

在宿主機的 /mnt/src/docker-containers/wyrover-mysql/mysql-data 創(chuàng)建目錄

在 wyrover-mysql 目錄下創(chuàng)建 start-server.sh

docker run --name wyrover-mysql -v /mnt/src/docker-containers/wyrover-mysql/mysql-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=password -d mysql:latest

啟動后可在 mysql-data 目錄下看到相關的數(shù)據(jù)庫文件

然后在啟一個 docker 容器連一下, 在 wyrover-mysql 目錄下創(chuàng)建 start-client.sh

docker run -it --link wyrover-mysql:mysql --rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'

在宿主 bash 下運行

./start-client.sh

就登錄到了 mysql,然后查看數(shù)據(jù)庫

show databases;

整個過程

docker@default:/mnt/src/docker-containers/wyrover-mysql$ ./start-client.sh
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 3
Server version: 5.7.16 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> exit;
Bye
docker@default:/mnt/src/docker-containers/wyrover-mysql$

links

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容