一、authentication plugin ‘caching_sha2_password’ -navicat连接问题解决

安装:https://dev.mysql.com/downloads/mysql/

原因:mysql版本身份验证引起的,

官网解释:https://dev.mysql.com/doc/refman/8.0/en/caching-sha2-pluggable-authentication.html

解决方法:

修改加密方式如下:


// 修改加密规则
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; 
// 更新一下用户的密码 
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
// 刷新权限 
FLUSH PRIVILEGES;
// 最后重置下密码:
alter user 'root'@'localhost' identified by '123456';

(1)#default_authentication_plugin=caching_sha2_password=>修改为

default_authentication_plugin=mysql_native_password

(2)修改配置文件

配置:引用MySql.Data.dll 需要修改配置文件(MySQL8.0默认配置文件为隐藏my.ini ;
(/ProgramData\MySQL\MySQL Server 8.0)
Mysql8.0配置问题

(3)重启服务

二、测试语句:


             String connecStr = "server=127.0.0.1;port=3306;user=root;password=***;database=***;";            
             MySqlConnection conn = new MySqlConnection(connecStr);
            try
            {
                conn.Open();//打开通道,建立连接,可能出现异常,使用try catch语句
                Console.WriteLine("已经建立连接");
                //在这里使用代码对数据库进行增删查改
            }
            catch (MySqlException ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                conn.Close();
            }

相关文章:

  • 2022-12-23
  • 2021-12-10
  • 2022-02-07
  • 2021-04-14
  • 2021-06-02
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-08
  • 2022-12-23
  • 2021-12-18
  • 2021-04-19
  • 2021-06-21
相关资源
相似解决方案