In this article I will explain with an example, how to resolve the following error: Authentication to host 'localhost' for user 'root' using method 'mysql_native_password' failed with message while working with MySQL database.
 
 

Error

This error occurs due to the following reason in MySQL database.
1. Specified Database in the connection string does not exist.
MySqlException Authentication to host for user using method failed with message in MySql Database
 
In the below connection string, the Initial Catalog (database name) is incorrect.
<connectionStrings>
    <add name="constr" connectionString="Data Source=localhost;port=3306;Initial Catalog=Northwind;User Id=root;password=pass@123" />
</connectionStrings>
 
 

Solution

Following is the solution for the above error.
1. Make sure that the Initial Catalog (database name) exists in the connection string as shown below.
<connectionStrings>
    <add name="constr" connectionString="Data Source=localhost;port=3306;Initial Catalog=ajaxsamples;User Id=root;password=pass@123" />
</connectionStrings>