简体   繁体   English

使用方法 'mysql_native_password' 对用户 'root' 的主机 'localhost' 进行身份验证失败并显示消息:未知数据库 'xxx'

[英]Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message: Unknown database 'xxx'

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" />

PS: It's running fine on the other system. PS:它在其他系统上运行良好。

Your connection string is demanding a MySQL database called cps .您的连接字符串需要一个名为cps的 MySQL 数据库。 It seems likely you have not yet created that database on your local MySQL server.您似乎尚未在本地 MySQL 服务器上创建该数据库。

Pro tip: Always read error message text carefully, asking yourself "what could this mean?"专业提示:始终仔细阅读错误消息文本,问自己“这意味着什么?”

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"/>

=> 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

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"; 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在连接字符串中将 localhost 修复为 127.0.0.1

Thanks for all the answers, But in my case as @GirishBabuC said its port and need to append the port in connection string in case you are using other then default port.感谢您提供所有答案,但在我的情况下,@GirishBabuC 表示其端口,并且需要在连接字符串中附加端口,以防您使用其他默认端口。

<add name="constring" connectionString="Server=localhost;Uid=root;Database=databasename;Port=3307;" providerName="MySql.Data.MySqlClient"/>

in my case its 3307.就我而言,它是 3307。

while installing its asks for port.安装时询问端口。

This issue could come up depending on which version of MySQL is being targeted.这个问题可能会出现,具体取决于所针对的 MySQL 版本。 You are welcome to try this solution to see if it works for you.欢迎您尝试此解决方案,看看它是否适合您。 Instead of using the Uid=*;Pwd=*;而不是使用Uid=*;Pwd=*; format, make use of the user=*;password=*;格式,使用user=*;password=*; format.格式。

Original Connection String:原始连接字符串:

Server=localhost;Port=3306;Database=databasename;Uid=sqltracking;Pwd=sqltracking;

One that works一个有效的

server=localhost;port=3306;database=databasename;user=sqltracking;password=sqltracking;

The first method works on MySql 8, but not on MySql 5.第一种方法适用于 MySql 8,但不适用于 MySql 5。

I haven't dug into the documentation behind these connection string configurations, however, I have noticed a difference between MySQL 5.7 and 8.0.我没有深入研究这些连接字符串配置背后的文档,但是,我注意到 MySQL 5.7 和 8.0 之间的差异。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用方法 &#39;mysql_native_password&#39; 对用户 &#39;root&#39; 的主机 &#39;localhost&#39; 进行身份验证失败并显示消息(使用密码:否) - Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message (using password: NO) 使用方法“mysql_native_password”对用户“用户名”的主机“192.168.0.31”进行身份验证失败,并显示消息:未知数据库“mysql57” - Authentication to host '192.168.0.31' for user 'username' using method 'mysql_native_password' failed with message: Unknown database 'mysql57' 使用方法“ mysql_native_password”对主机或用户进行身份验证失败 - authentication to host or user using method 'mysql_native_password' failed 参考:使用方法“ mysql_native_password”对主机进行MySql连接器/网络身份验证失败 - Reference: MySql Connector/Net Authentication to host using method 'mysql_native_password' failed 使用方法 mysql_native_password 验证失败 - Authentication failed using method mysql_native_password 使用方法“ mysql_native_password”失败 - using method 'mysql_native_password' failed 通过 mysql_native_password 更改用户 root@localhost 标识; -- 因语法错误而失败 - ALTER USER root@localhost IDENTIFIED VIA mysql_native_password; -- fails with syntax error C# - 意外的身份验证方法 mysql_native_password 异常 - C# - Unexpected authentication method mysql_native_password exception MySQL 5.1:检查 MySQL 服务器版本以获取在 &#39;USER &#39;user&#39;@&#39;localhost&#39; IDENTIFIED WITH mysql_native_password BY &#39;password&#39;&#39; 附近使用的正确语法 - MySQL 5.1: Check MySQL server version for the right syntax to use near 'USER 'user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'' 从流读取失败 - mysql_native_password错误 - Reading from stream failed - mysql_native_password error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM