運行 docker pull mysqlmysql
[root@MyCentos7-1 ~]# docker pull mysql Using default tag: latest latest: Pulling from library/mysql 85b1f47fba49: Pull complete 2a809168ab45: Pull complete Digest: sha256:1a2f9361228e9b10b4c77a651b460828514845dc7ac51735b919c2c4aec864b7 Status: Downloaded newer image for mysql:latest
[root@MyCentos7-1 ~]# docker run --restart=always --name kitking-mysql -e MYSQL_ROOT_PASSWORD=rad_xxx -p 3306:3306 -d mysql eb3dbfb0958f5c856323e4d8da60d43194884ff05d7adac1ec059adb66ac7f7b
docker run是啓動容器的命令;sql
--name:指定了容器的名稱,方便以後進入容器的命令行docker
-itd:其中,i是交互式操做,t是一個終端,d指的是在後臺運行bash
-p:指在本地生成一個隨機端口,用來映射mysql的3306
端口
工具
-e:設置環境變量測試
MYSQL_ROOT_PASSWORD=emc123123:指定了mysql的root密碼spa
mysql:指運行mysql鏡像命令行
運行 docker exec -it kitking-mysql /bin/bash3d
[root@MyCentos7-1 ~]# docker exec -it kitking-mysql /bin/bash root@my-mysql-v1-nths4:/usr/local/mysql#
運行 mysql -uroot -prest
root@my-mysql-v1-nths4:/usr/local/mysql# mysql -uroot -p Enter password: mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.02 sec)
接着,因爲mysql中root執行綁定在了localhost
,所以須要對root進行受權,代碼以下,
mysql> ALTER user 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
最後,使用navitecat測試mysql鏈接,以下,