MySQL8.0登录提示caching_sha2_password问题

MySQL8.0登录提示caching_sha2_password问题解决方法

用dock构建mysql8后,phpmyadmin登陆遇到问题:
caching_sha2_password

  1. 方法一(适用于mysql8 安装前)
    a.修改my.cnf文件,添加如下代码:
default_authentication_plugin=mysql_native_password

b. 通过dock 构建mysql8

c.登陆mysql容器查看是否成功:

[root@localhost docker]# docker-compose exec mysql8 bash

root@e882fbe17adb:/# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.27 MySQL Community Server - GPL

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> select Host, User, plugin from user;
+-----------+------------------+-----------------------+
| Host      | User             | plugin                |
+-----------+------------------+-----------------------+
| %         | root             | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
| localhost | root             | mysql_native_password |
+-----------+------------------+-----------------------+
5 rows in set (0.00 sec)

root 的用户身份已经变为mysql_native_password

  1. 方法2(实用mysql8已经构建完成)
    a. 登陆mysql容器:
[root@localhost docker]# docker-compose exec mysql8 bash

root@e882fbe17adb:/# mysql -u root -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 9
    Server version: 8.0.27 MySQL Community Server - GPL

    Copyright (c) 2000, 2021, 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> 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> select Host, User, plugin from user;
+-----------+------------------+-----------------------+
| Host      | User             | plugin                |
+-----------+------------------+-----------------------+
| %         | 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 |
+-----------+------------------+-----------------------+
5 rows in set (0.00 sec)

可看见root的plugin为caching_sha2_password

b.修改caching_sha2_password

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
    Query OK, 0 rows affected (0.00 sec)

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
    Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.01 sec)

c.查看是否修改成功

mysql> select Host, User, plugin from user;
+-----------+------------------+-----------------------+
| Host      | User             | plugin                |
+-----------+------------------+-----------------------+
| %         | root             | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
| localhost | root             | mysql_native_password |
+-----------+------------------+-----------------------+
5 rows in set (0.00 sec)

可看见root的plugin为caching_sha2_password

问题解决!

你可能感兴趣的:(MySQL8.0登录提示caching_sha2_password问题)