【问题标题】:Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message (using password: NO)使用方法'mysql_native_password'对用户'root'的主机'localhost'进行身份验证失败并显示消息(使用密码:否)
【发布时间】:2017-01-19 09:49:38
【问题描述】:

你们能帮我完成我的论文吗?这是我系统中的问题之一。

MySqlConnection cn2 = new MySqlConnection(cn.ConnectionString);
cn2.Open();-->>> Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message: Access denied for user 'root'@'localhost' (using password: NO)

listView1.Items.Clear();
string sql = "Select * from tblrecord where DateTime between '" + dateTimePicker1.Value + "' and '" + dateTimePicker2.Value + "'";
cm = new MySqlCommand(sql);
//cm = new MySqlCommand(sql, cn1);
dr = cm.ExecuteReader();
dr.Read();
if (dr.HasRows)

【问题讨论】:

  • 问题出在“cn2.Open();”
  • 我们可以看看你的连接字符串(我知道它是私有的,但我只问,因为它没有密码,根据错误)。或者你的 mysql 服务器还没有允许没有密码的 root 访问。
  • 我应该怎么做才能纠正它?
  • 转到您的 mysql 服务器,并使用您定义的密码创建一个新用户。使用该用户从 Visual Studio 登录。这是因为使用 root 帐户登录通常并不常见,但如果您坚持,您将需要找出您的默认 root 密码并使用它。

标签: c# mysql


【解决方案1】:

只需在连接字符串中添加密码,因为您尚未在连接中添加密码。

【讨论】:

    猜你喜欢
    • 2016-10-27
    • 2021-08-23
    • 2017-10-14
    • 2022-11-24
    • 1970-01-01
    • 2019-10-09
    • 2013-07-12
    • 1970-01-01
    相关资源
    最近更新 更多