DbContextOptionsBuilder has no UseMySql method
UseMysql is not found on DbContextOptionsBuilderShort answer
UseMySql comes from a provider package, not from EF Core itself. Install Pomelo.EntityFrameworkCore.MySql in the project that calls it, spell the method UseMySql with a capital S, and pass a server version. Match the package release to your EF Core version.
Fix it fast
1Find out which cause you have
List the packages in the project that contains the call. If no MySQL provider shows up, that is the answer.
dotnet list package | findstr /i "mysql EntityFrameworkCore"2Match what you see, then jump to its fix
- 1
dotnet list package shows Microsoft.EntityFrameworkCore but nothing with MySql in the nameNo MySQL provider package is installed in that projectFix - 2
The compiler error says UseMysqlThe method name is spelled with the wrong capitalsFix - 3
The package restores, but versions of Microsoft.EntityFrameworkCore and the provider do not share a major numberThe Pomelo release does not match the EF Core versionFix
- 1
What does the error look like?
UseMysql is not found on DbContextOptionsBuilderCannot find the UseMysql method on DbContextOptions
Cause 1 of 3
No MySQL provider package is installed in that project
1Check
Microsoft documents database providers as separate NuGet packages that you install and then configure in the DbContext. For MySQL and MariaDB, its provider list names Pomelo.EntityFrameworkCore.MySql, and the Pomelo readme shows the UseMySql call.
dotnet list package2Fix
Add the package to the project that registers the DbContext, then call UseMySql with a connection string and a server version.
dotnet add package Pomelo.EntityFrameworkCore.MySql
var serverVersion = ServerVersion.AutoDetect(connectionString);
services.AddDbContext<AppDbContext>(o => o.UseMySql(connectionString, serverVersion));3Verify
The project builds, and the error under UseMySql disappears.
dotnet buildConfirmed by learn.microsoft.com
Cause 2 of 3
The method name is spelled with the wrong capitals
1Check
Pomelo's own sample calls the method UseMySql, with a capital S.
grep -rn "UseMysql" --include=*.cs .2Fix
Rename the call to UseMySql. For MariaDB the Pomelo page says to use MariaDbServerVersion as the version object.
options.UseMySql(connectionString, new MariaDbServerVersion(new Version(10, 11, 0)));3Verify
The build succeeds.
dotnet buildConfirmed by github.com
Cause 3 of 3
The Pomelo release does not match the EF Core version
1Check
Microsoft warns that providers typically do not work across major EF Core versions. The Pomelo page maps each release to one EF Core line: 9.0.0 to EF Core 9.0.x, 8.0.3 to 8.0.x, 7.0.0 to 7.0.x. It also lists the minimum MySqlConnector version for each.
dotnet list package --include-transitive | findstr /i "EntityFrameworkCore MySqlConnector"2Fix
Move the provider to the release that belongs to your EF Core line, or move EF Core to the line the provider supports.
dotnet add package Pomelo.EntityFrameworkCore.MySql --version 9.0.03Verify
The restore finishes with no version warning and the build passes.
dotnet restore && dotnet buildConfirmed by github.com
How do I stop it coming back?
- Put the provider package in the same project that calls AddDbContext.
- Upgrade EF Core and the provider package in the same commit.
- Read the compatibility table on the provider page before moving to a new .NET version.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Databases
EF Core logs 'An error occurred using the connection to database' with MySQL
Can't connect to MySQL server on 'host_name' (111)
This EF Core message is only a wrapper.
3 causes, each with a fixDatabases
There is already an open DataReader on the MySQL connection
The error appears inside a while (reader.Read()) loop
One MySQL connection runs one operation at a time.
3 causes, each with a fixDatabases
C# INSERT fails with 'Fatal error encountered during command execution'
MySql.Data.MySqlClient.MySqlException: Fatal error encountered during command execution
A fatal error during command execution means the connection broke while the INSERT was in flight.
3 causes, each with a fixDatabases
MySqlException: Timeout expired in a .NET app
MySql.Data.MySqlClient.MySqlException: Timeout expired
Timeout expired means a wait ended before it finished.
3 causes, each with a fixDatabases
C# cannot reach MySQL: connection attempt failed, no response in time
System.Net.Sockets.SocketException (10060)
SocketError 10060 means the connection attempt timed out, or the host did not respond.
3 causes, each with a fixDatabases
MySqlException: unable to connect to any of the specified MySQL hosts
Can't connect to MySQL server on 'host' (10061)
The connector could not open a TCP connection to the host and port in your connection string.
4 causes, each with a fix