Bug #107817 Authentication through MySql.Data fails after upgrading to .Net 6
Submitted: 8 Jul 2022 15:23 Modified: 15 Jul 2022 17:06
Reporter: Mats Taste Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:8.0.29 OS:Windows
Assigned to: CPU Architecture:Any
Tags: DotNet Framework-6

[8 Jul 2022 15:23] Mats Taste
Description:
I have a .Net 5 solution (MVC webapp) which uses the MySql.Data (8.0.29) nuget package to connect to a 5.7 MySql server (local). The solution works as expected.

Now I upgraded the Solution to .Net 6. This was done by simply changing the TargetFramework in each of the solution projects. When I run the project now any attempt to establish a connection fails with the following error:

MySql.Data.MySqlClient.MySqlException
  HResult=0x80004005
  Message=Authentication to host 'localhost' for user 'bogususer' using method 'mysql_native_password' failed with message: Access denied for user 'bogususer'@'localhost' (using password: YES)

Reverting the project back to .Net 5 fixes the problem. 

How to repeat:
Create a simple .Net 5 MVC project in Visual Studio and use the MySql.Data (8.0.29) nuget package as a database connector and Dapper (latest version) as the ORM. Use a connection string with a plain password, similar to this one:

"Server=localhost;Port=3306;Database=mydb;user id=my_user;password=VerrrySecret_1234"

Establish a connection to the database and run some queries. Should work.

Now go through all the projects in your solution and change the TargetFramework from .Net 5.0 to .Net 6.0. Run the project again. Should fail.
[11 Jul 2022 12:03] MySQL Verification Team
Hi Mr. Taste,

Thank you for your bug report.

However, you can not use 8.0 client with 5.7 server.

There is a workaround, which is to configure 8.0 client to use native password. This is because the default for 8.0 is to use highly encrypted password.

Not a bug.
[15 Jul 2022 17:06] Mats Taste
Hello!

Please review this because I still think it is a bug. I have now used a MySql 8.0 database instead of 5.7 but I run into exactly the same problem.

The code to execute the sql statement is very basic and I use a similar connection string as in my original post.

using var con = new MySqlConnection(alteredConString);
con.Open(); // fails with the exception

If I run this code from within a .net 5 project it works fine. Running the same code using the same connectionstring from within a .net 6 solution fails with the MySql.Data.MySqlClient.MySqlException:

{"Authentication to host 'localhost' for user 'xxx' using method 'mysql_native_password' failed with message: Access denied for user 'xxx'@'localhost' (using password: YES)"}

I would really appreciate if you would try this out before marking it Not a bug. Thank you in advance!
[20 Feb 2024 10:37] chaima br
Have you found a resolution for this issue ? As I'm having the same.