docker pull mysql //下載鏡像
docker run --name mysql01 -d mysql //啟動(dòng)容器
這樣啟動(dòng)容器并不能正常運(yùn)行
通過(guò) `docker logs`可以看到說(shuō)需要設(shè)置mysql的密碼
有問(wèn)題的容器噪奄,直接`docker rm 78c308e8939f`刪除
docker run --name mysql01 -e MYSQL_ROOT_PASSWORD=123456 -d mysql//啟動(dòng)mysql容器
mysql的root用戶密碼是123456
由于沒(méi)有做端口映射祈噪,所以也不能訪問(wèn)
docker run -p 3306:3306 --name mysql02 -e MYSQL_ROOT_PASSWORD=123456 -d mysql
端口號(hào)映射
root密碼
后臺(tái)運(yùn)行
完整過(guò)程
huangchengdudeMacBook-Pro:docker huangchengdu$ docker run --name mysql -p 3308:3306 -e MYSQL_ROOT_PASSWORD=huang303513 -d mysql
1e3136fc1dcd96302404752543a78a853a7586cc1b089d5b9e854d002f41178d
huangchengdudeMacBook-Pro:docker huangchengdu$ docker exec -it mysql bash
root@1e3136fc1dcd:/# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.13 MySQL Community Server - GPL
Copyright (c) 2000, 2018, 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> select host,user,plugin,authentication_string from mysql.user;
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| host | user | plugin | authentication_string |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| % | root | caching_sha2_password | $A$005$8E<2 WTQ@ Pg-JqsD0/UA2DBLE8KDa/LqfF9FN.bWU2yYXtxnWtwtBc2 |
| 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$fam3B=^X9Otm>lDeyJqjqmQJg/jeSY/dUq8xerDX091FkOFUpE3jE0// |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
5 rows in set (0.00 sec)
mysql> history
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'history' at line 1
mysql> create user 'huang303513'@'%' INENTIFIED BY 'huang303513';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INENTIFIED BY 'huang303513'' at line 1
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> create user 'huang303513'@'%' IDENTIFIED BY 'huang303513';
Query OK, 0 rows affected (0.09 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
修改密碼的模式
huangchengdudeMacBook-Pro:docker huangchengdu$ docker exec -it mysql bash
root@1e3136fc1dcd:/# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 8.0.13 MySQL Community Server - GPL
Copyright (c) 2000, 2018, 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> select host,user,plugin,authentication_string from mysql.user;
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
| host | user | plugin | authentication_string |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
\_&ZzKovpgYEn7ImvChFqIo2NuI1ET89rb7ihjvtNdFkvpEB |word | $A$005$ "eXU,Y1R
| % | root | caching_sha2_password | $A$005$8E<2 WTQ@ Pg-JqsD0/UA2DBLE8KDa/LqfF9FN.bWU2yYXtxnWtwtBc2 |
| 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$fam3B=^X9Otm>lDeyJqjqmQJg/jeSY/dUq8xerDX091FkOFUpE3jE0// |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
6 rows in set (0.00 sec)
mysql> select host,user,plugin from mysql.user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | huang303513 | caching_sha2_password |
| % | root | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
| localhost | root | caching_sha2_password |
+-----------+------------------+-----------------------+
6 rows in set (0.00 sec)
mysql> mysql version
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql version' at line 1
mysql> SHOW VARIABLES LIKE "%version%";
+-------------------------+------------------------------+
| Variable_name | Value |
+-------------------------+------------------------------+
| innodb_version | 8.0.13 |
| protocol_version | 10 |
| slave_type_conversions | |
| tls_version | TLSv1,TLSv1.1,TLSv1.2 |
| version | 8.0.13 |
| version_comment | MySQL Community Server - GPL |
| version_compile_machine | x86_64 |
| version_compile_os | Linux |
| version_compile_zlib | 1.2.11 |
+-------------------------+------------------------------+
9 rows in set (0.01 sec)
mysql> ALTER user 'huang303513'@'%' IDENTIFIED WITH mysql_native_password BY 'huang303513';
Query OK, 0 rows affected (0.09 sec)
mysql> ALTER user 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'huang303513';
Query OK, 0 rows affected (0.03 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> select host,user,plugin from mysql.user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | huang303513 | mysql_native_password |
| % | root | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
| localhost | root | caching_sha2_password |
+-----------+------------------+-----------------------+
6 rows in set (0.00 sec)
mysql>