1. 程式人生 > >Docker-4:Mysql安裝

Docker-4:Mysql安裝

一、搜尋並下載

$ docker search mysql
$ docker pull mysql

二、啟動並設定掛載路徑

docker run -d -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 --name mysql -v /data/docker/mysql/data:/var/lib/mysql -v /data/docker/mysql/conf.d/mysql.cnf:/etc/mysql/conf.d/mysql.cnf mysql

三、檢視已啟動的映象

[[email protected] data]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                        NAMES
ffb3f6402ace        29e0ae3b69b9        "docker-entrypoint..."   25 minutes ago      Up 25 minutes       0.0.0.0:3306->3306/tcp, 33060/tcp            mysql

四、使用客戶端連結

解決:

     1、進入mysql容器

docker exec -it mysql /bin/bash

     2、登入mysql修改

/usr/bin/mysql -uroot -p123456

     3、修改

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)  

mysql> select host,user,plugin,authentication_string from mysql.user;
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| host      | user             | plugin                | authentication_string                                                  |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| %         | root             | mysql_native_password | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9                              |
| localhost | mysql.infoschema | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session    | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys        | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root             | caching_sha2_password | $A$005$;H1`RFW%
                                                                        9j
                                                                          aqgcTZqBNFdZzQBQL6rhyKNtG028.nc4V6ceQb8q5dLJ7 |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
5 rows in set (0.04 sec)