CentOS

Dokcer mysql 无法连接

2023-03-04  本文已影响0人  Rinaloving

mysql 无法连接

1. 解决

docker exec -it mysql1 /bin/bash
mysql -u root -p
 ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
select host,user,plugin,authentication_string from mysql.user;
root@Pomelo:~# docker exec -it mysql1 /bin/bash
bash-4.4# ls
bin  boot  dev  docker-entrypoint-initdb.d  entrypoint.sh  etc  home  lib  lib64  media  mnt  mysql  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
bash-4.4# whereis mysql
bash: whereis: command not found
bash-4.4# cd mysql/
bash-4.4# ls
bash-4.4# cd ..
bash-4.4# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.32 MySQL Community Server - GPL

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.21 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$*Fe\Uv}X-@?%L7vmwodbeCTCMRNJuRlISFbP/2D6FDyjPkzYqrltE5Pi7 |
+-----------+------------------+-----------------------+------------------------------------------------------------------------+
5 rows in set (0.00 sec)

mysql> 

2. 再次连接

QQ截图20230305233341.png

3. 补充

4. 参考文档

上一篇 下一篇

猜你喜欢

热点阅读