背景
記錄下如何使用docker容器操作mysql數據庫
方法
1、下載鏡像
$ docker pull mysql:5.6
2、運行容器
$ docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root mysql:5.6
-e指定環境變量
3、進入容器
C:\Users\songzeceng>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
699ed4931f3e mysql:5.6 "docker-entrypoint.s…" 13 seconds ago Up 7 seconds 0.0.0.0:3306->3306/tcp pensive_brattain
C:\Users\songzeceng>docker exec -it 699ed4931f3e /bin/bash
root@699ed4931f3e:/#
4、運行Mysql,輸入密碼root
root@699ed4931f3e:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.47 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>