一、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)
(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();
}