MySQL 使用方法 'mysql_native_password' 对用户 'root' 的主机 'localhost' 进行身份验证失败并显示消息:未知数据库 'xxx'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38027830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message: Unknown database 'xxx'
提问by diamond421
I am using code first approach in my project. But when i am trying to run db-migrations by using 'update-database' command i am getting null reference exception and when I am running the application I am getting the following configuration error: Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message: Unknown database 'xxx'.
我在我的项目中使用代码优先方法。但是,当我尝试使用“update-database”命令运行 db-migrations 时,出现空引用异常,并且在运行应用程序时出现以下配置错误:Authentication to host 'localhost' for user 'root'使用方法 'mysql_native_password' 失败并显示消息:未知数据库 'xxx'。
Here is the connection string:
这是连接字符串:
<add name="DefaultConnectionString" connectionString="server=localhost;port=3306;Database=cps;uid=root;pwd=root;" providerName="MySql.Data.MySqlClient" />
P.S: It's running fine on the other system.
PS:它在其他系统上运行良好。
回答by O. Jones
Your connection string is demanding a MySQL database called cps
. It seems likely you have not yet created that database on your local MySQL server.
您的连接字符串需要一个名为cps
. 您似乎尚未在本地 MySQL 服务器上创建该数据库。
Pro tip: Always read error message text carefully, asking yourself "what could this mean?"
专业提示:始终仔细阅读错误消息文本,问自己“这意味着什么?”
回答by GirishBabuC
The solution I got for below error.
我得到以下错误的解决方案。
Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message: Access denied for user 'root'@'localhost' (using password: YES)
使用方法 'mysql_native_password' 对用户 'root' 的主机 'localhost' 进行身份验证失败并显示消息:用户 'root'@'localhost' 的访问被拒绝(使用密码:是)
<add name="constring" connectionString="Server=localhost;Uid=root;Database=databasename;Port=3306;" providerName="MySql.Data.MySqlClient"/>
<add name="constring" connectionString="Server=localhost;Uid=root;Database=databasename;Port=3306;" providerName="MySql.Data.MySqlClient"/>
=> Just remove the password
=> 只需删除密码
=> If you have 2 local servers with a different port number, just add it or else by default it will take 3306
=> 如果您有 2 个具有不同端口号的本地服务器,只需添加它,否则默认情况下它将占用3306
回答by Lermpon Pati
Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message: Access denied for user 'root'@'localhost' (using password: YES)
使用方法 'mysql_native_password' 对用户 'root' 的主机 'localhost' 进行身份验证失败并显示消息:用户 'root'@'localhost' 的访问被拒绝(使用密码:是)
from
从
public string strconn = "SERVER = localhost ;DATABASE=restaurant;UID = root;pwd=12345678;convert zero datetime=True";
public string strconn = "SERVER = localhost ;DATABASE=restaurant;UID = root;pwd=12345678;convert zero datetime=True";
become
变得
public string strconn = "SERVER =127.0.0.1 ;DATABASE=restaurant;UID = root;pwd=12345678;convert zero datetime=True"; fix localhost to 127.0.0.1 in connectionstring
public string strconn = "SERVER =127.0.0.1 ;DATABASE=restaurant;UID = root;pwd=12345678;convert zero datetime=True"; 在连接字符串中将 localhost 修复为 127.0.0.1