Docker搭建MySQL數據庫


1、docker 可以執行如下命令一步搭建MySQL數據庫:

docker run --name mysql -v $PWD/mysql:/var/lib/mysql -p3306:3308 -eMYSQL_ROOT_PASSWORD=123456 -d mysql:5.7

命令中顯示我們使用的是Docker技術並創建一個名字為mysql的容器,然后在容器中把數據關聯到本地的MySQL,並把MySQL的3306接口映射到外面的3308,同時為用戶設置一個賬戶密碼

2、進入鏡像

docker exec -it mysql bash

3、連接mysql

執行命令: mysql -h127.0.0.1 -p
root@706629fa5ef0:/# mysql -h127.0.0.1 -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.29 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, 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>

查看數據庫:

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM