参考:https://www.cnblogs.com/wu-guo-xing/p/9970244.html

    本次使用的是 docker 部署的

    1. xiaohui@DESKTOP-44T4DSR:/mnt/c/Users/xiaohui$ docker run -d -p13306:3306 --name some-mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:8.0.26
    2. 8ba4f33b2df772f8157d41cca8203e6af7e5a272a027345a60165055ae38fc21
    3. xiaohui@DESKTOP-44T4DSR:/mnt/c/Users/xiaohui$
    4. xiaohui@DESKTOP-44T4DSR:/mnt/c/Users/xiaohui$
    5. xiaohui@DESKTOP-44T4DSR:/mnt/c/Users/xiaohui$ docker ps
    6. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    7. 8ba4f33b2df7 mysql:8.0.26 "docker-entrypoint.s…" 6 seconds ago Up 4 seconds 33060/tcp, 0.0.0.0:13306->3306/tcp, :::13306->3306/tcp some-mysql
    8. xiaohui@DESKTOP-44T4DSR:/mnt/c/Users/xiaohui$

    navicat 无法连接,报错
    image.png
    简单采用 mysql_native_password 方式加密密码,操作如下:

    1. # mysql -uroot -p123456
    2. mysql: [Warning] Using a password on the command line interface can be insecure.
    3. Welcome to the MySQL monitor. Commands end with ; or \g.
    4. Your MySQL connection id is 21
    5. Server version: 8.0.26 MySQL Community Server - GPL
    6. Copyright (c) 2000, 2021, Oracle and/or its affiliates.
    7. Oracle is a registered trademark of Oracle Corporation and/or its
    8. affiliates. Other names may be trademarks of their respective
    9. owners.
    10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    11. mysql>
    12. mysql> use mysql;
    13. Reading table information for completion of table and column names
    14. You can turn off this feature to get a quicker startup with -A
    15. Database changed
    16. mysql> select host,user from user;
    17. +-----------+------------------+
    18. | host | user |
    19. +-----------+------------------+
    20. | % | root |
    21. | localhost | mysql.infoschema |
    22. | localhost | mysql.session |
    23. | localhost | mysql.sys |
    24. | localhost | root |
    25. +-----------+------------------+
    26. 5 rows in set (0.00 sec)
    27. mysql> select null = null, version();
    28. +-------------+-----------+
    29. | null = null | version() |
    30. +-------------+-----------+
    31. | NULL | 8.0.26 |
    32. +-------------+-----------+
    33. 1 row in set (0.00 sec)
    34. mysql> alter user 'root'@'%' identified WITH mysql_native_password by '123456';
    35. Query OK, 0 rows affected (0.02 sec)
    36. mysql> flush privileges;
    37. Query OK, 0 rows affected (0.01 sec)
    38. mysql>

    主要使用该句命令:alter user ‘root’@’%’ identified WITH mysql_native_password by ‘123456’;
    查看用户加密使用的插件 plugin : select host,user,plugin from mysql.user;

    1. show VARIABLES like '%password%';
    2. show variables;
    3. select host,user,plugin from mysql.user;
    4. mysql> select host,user,plugin from mysql.user;
    5. +-----------+------------------+-----------------------+
    6. | host | user | plugin |
    7. +-----------+------------------+-----------------------+
    8. | % | root | mysql_native_password |
    9. | localhost | mysql.infoschema | caching_sha2_password |
    10. | localhost | mysql.session | caching_sha2_password |
    11. | localhost | mysql.sys | caching_sha2_password |
    12. | localhost | root | caching_sha2_password |
    13. +-----------+------------------+-----------------------+
    14. 5 rows in set (0.00 sec)
    15. mysql>

    mysql8 默认的鉴权加密 default_authentication_plugin caching_sha2_password

    1. mysql> show variables like 'default_authentication_plugin';
    2. +-------------------------------+-----------------------+
    3. | Variable_name | Value |
    4. +-------------------------------+-----------------------+
    5. | default_authentication_plugin | caching_sha2_password |
    6. +-------------------------------+-----------------------+
    7. 1 row in set (0.00 sec)
    8. mysql>

    mysql5.7 是 mysql_native_password。