赞
踩
官网解释: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';
配置:引用MySql.Data.dll 需要修改配置文件(MySQL8.0默认配置文件为隐藏my.ini ;
(/ProgramData\MySQL\MySQL Server 8.0)
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(); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。