MySqlConnector 2.4.0

Prefix Reserved
dotnet add package MySqlConnector --version 2.4.0                
NuGet\Install-Package MySqlConnector -Version 2.4.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MySqlConnector" Version="2.4.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MySqlConnector --version 2.4.0                
#r "nuget: MySqlConnector, 2.4.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MySqlConnector as a Cake Addin
#addin nuget:?package=MySqlConnector&version=2.4.0

// Install MySqlConnector as a Cake Tool
#tool nuget:?package=MySqlConnector&version=2.4.0                

About

MySqlConnector is a C# ADO.NET driver for MySQL, MariaDB, Amazon Aurora, Azure Database for MySQL and other MySQL-compatible databases.

More documentation is available at the MySqlConnector website.

How to Use

// set these values correctly for your database server
var builder = new MySqlConnectionStringBuilder
{
	Server = "your-server",
	UserID = "database-user",
	Password = "P@ssw0rd!",
	Database = "database-name",
};

// open a connection asynchronously
using var connection = new MySqlConnection(builder.ConnectionString);
await connection.OpenAsync();

// create a DB command and set the SQL statement with parameters
using var command = connection.CreateCommand();
command.CommandText = @"SELECT * FROM orders WHERE order_id = @OrderId;";
command.Parameters.AddWithValue("@OrderId", orderId);

// execute the command and read the results
using var reader = await command.ExecuteReaderAsync();
while (reader.Read())
{
	var id = reader.GetInt32("order_id");
	var date = reader.GetDateTime("order_date");
	// ...
}

ASP.NET

For ASP.NET, use the MySqlConnector.DependencyInjection package to integrate with dependency injection and logging.

var builder = WebApplication.CreateBuilder(args);

// use AddMySqlDataSource to configure MySqlConnector
builder.Services.AddMySqlDataSource(builder.Configuration.GetConnectionString("Default"));

var app = builder.Build();

// use dependency injection to get a MySqlConnection in minimal APIs or in controllers
app.MapGet("/", async (MySqlConnection connection) =>
{
    // open and use the connection here
    await connection.OpenAsync();
    await using var command = connection.CreateCommand();
    command.CommandText = "SELECT name FROM users LIMIT 1";
    return "Hello World: " + await command.ExecuteScalarAsync();
});

app.Run();

Key Features

  • Full support for async I/O
  • High performance
  • Supports .NET Framework, .NET Core, and .NET 5.0+

Main Types

The main types provided by this library are:

  • MySqlConnection (implementation of DbConnection)
  • MySqlCommand (implementation of DbCommand)
  • MySqlDataReader (implementation of DbDataReader)
  • MySqlBulkCopy
  • MySqlBulkLoader
  • MySqlConnectionStringBuilder
  • MySqlConnectorFactory
  • MySqlDataAdapter
  • MySqlException
  • MySqlTransaction (implementation of DbTransaction)

Feedback

MySqlConnector is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 is compatible.  net472 was computed.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (596)

Showing the top 5 NuGet packages that depend on MySqlConnector:

Package Downloads
Pomelo.EntityFrameworkCore.MySql

Pomelo's MySQL database provider for Entity Framework Core.

SqlSugarCore

.Net Core3.1 .Net5 .Net6 .Net7 .Net8 安装此版本,好用的ORM框架 ,支持国外主流和国产人大金仓达梦 OceanBase GaussDB QuestDb ClickHouse Oracle MySql Gbase8s SqlServer Sqlite 等, 使用教程:https://www.donet5.com/Home/Doc?typeId=1226

DistributedLock

Provides easy-to-use mutexes, reader-writer locks, and semaphores that can synchronize across processes and machines. This is an umbrella package that brings in the entire family of DistributedLock.* packages (e. g. DistributedLock.SqlServer) as references. Those packages can also be installed individually.

AspNetCore.HealthChecks.MySql

HealthChecks.MySql is the health check package for MySQL.

Hangfire.MySqlStorage

Hangfire MySql Storage

GitHub repositories (122)

Showing the top 5 popular GitHub repositories that depend on MySqlConnector:

Repository Stars
dotnet/aspnetcore
ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
DapperLib/Dapper
Dapper - a simple object mapper for .Net
nopSolutions/nopCommerce
ASP.NET Core eCommerce software. nopCommerce is a free and open-source shopping cart.
dotnetcore/CAP
Distributed transaction solution in micro-service base on eventually consistency, also an eventbus with Outbox pattern
quartznet/quartznet
Quartz Enterprise Scheduler .NET
Version Downloads Last updated
2.4.0 4,340 11/12/2024
2.4.0-beta.2 1,274 10/20/2024
2.4.0-beta.1 693 10/14/2024
2.3.7 2,203,374 4/22/2024
2.3.6 421,960 3/20/2024
2.3.5 6,660,135 1/20/2024
2.3.4 225,710 1/14/2024
2.3.3 259,038 12/19/2023
2.3.2 11,124 12/18/2023
2.3.1 1,457,411 11/17/2023
2.3.0 138,988 11/14/2023
2.2.7 2,222,777 7/21/2023
2.2.6 1,484,093 5/4/2023
2.2.5 14,254,196 1/1/2023
2.2.4 102,429 12/23/2022
2.2.3 588,858 12/18/2022
2.2.2 685,278 12/6/2022
2.2.1 432,835 11/21/2022
2.2.0 794,777 11/8/2022
2.1.13 1,776,990 8/26/2022
2.1.12 152,393 8/12/2022
2.1.11 519,128 7/14/2022
2.1.10 1,562,515 6/4/2022
2.1.9 249,466 5/16/2022
2.1.8 1,094,463 3/7/2022
2.1.7 299,084 2/20/2022
2.1.6 87,141 2/10/2022
2.1.5 256,641 1/30/2022
2.1.4 105,752 1/25/2022
2.1.3 8,294 1/25/2022 2.1.3 is deprecated because it has critical bugs.
2.1.2 20,170,315 12/23/2021
2.1.1 10,815 12/21/2021
2.1.0 1,326,986 11/28/2021
2.0.0 5,489,610 11/9/2021
1.3.14 1,108,610 10/20/2021
1.3.13 3,110,419 10/2/2021
1.3.12 279,253 9/11/2021
1.3.11 2,474,322 7/2/2021
1.3.10 2,506,093 6/16/2021
1.3.9 596,399 5/27/2021 1.3.9 is deprecated because it has critical bugs.
1.3.8 389,701 4/30/2021 1.3.8 is deprecated because it has critical bugs.
1.3.7 1,917,472 4/24/2021 1.3.7 is deprecated because it has critical bugs.
1.3.6 3,689 4/24/2021 1.3.6 is deprecated because it has critical bugs.
1.3.5 8,755 4/23/2021 1.3.5 is deprecated because it has critical bugs.
1.3.4 126,807 4/21/2021 1.3.4 is deprecated because it has critical bugs.
1.3.3 153,712 4/12/2021 1.3.3 is deprecated because it has critical bugs.
1.3.2 656,065 3/22/2021 1.3.2 is deprecated because it has critical bugs.
1.3.1 189,401 3/11/2021 1.3.1 is deprecated because it has critical bugs.
1.3.0 206,060 3/7/2021 1.3.0 is deprecated because it has critical bugs.
1.2.1 1,189,003 12/12/2020
1.2.0 388,119 11/26/2020
1.1.0 2,667,393 11/10/2020
1.0.1 2,094,260 8/13/2020
1.0.0 2,451,585 7/11/2020
0.69.10 2,291,337 10/21/2020
0.69.9 4,132,739 8/20/2020
0.69.8 130,198 7/20/2020
0.69.7 6,171 7/16/2020
0.69.6 145,897 7/7/2020
0.69.5 82,581 7/1/2020
0.69.4 33,667 6/25/2020
0.69.3 189,515 6/16/2020
0.69.2 20,260 6/12/2020
0.69.1 9,872 6/10/2020
0.69.0 19,420 6/8/2020
0.68.1 6,525 6/8/2020
0.68.0 4,517 6/6/2020
0.67.0 68,816 5/30/2020
0.66.0 375,037 5/7/2020
0.65.0 30,363 5/3/2020
0.64.2 35,241 4/28/2020
0.64.1 30,248 4/26/2020
0.64.0 52,474 4/18/2020
0.63.2 245,934 4/9/2020
0.63.1 314,934 4/4/2020
0.63.0 49,393 3/26/2020
0.62.0 310,945 2/29/2020
0.61.0 7,866,296 11/5/2019
0.60.4 17,982 11/4/2019
0.60.3 357,909 10/28/2019
0.60.2 192,487 10/21/2019
0.60.1 7,388 10/20/2019
0.60.0 16,544 10/19/2019
0.59.2 1,807,876 10/4/2019
0.59.1 17,419 9/30/2019
0.59.0 30,099 9/25/2019
0.58.0 62,071 9/24/2019
0.57.0 8,624 9/23/2019
0.56.0 2,421,377 5/26/2019
0.55.0 36,282 5/24/2019
0.54.0 69,996 5/11/2019
0.53.0 170,202 4/19/2019
0.52.0 150,047 4/11/2019
0.51.1 124,606 3/27/2019
0.51.0 9,086 3/27/2019
0.50.0 45,032 3/18/2019
0.49.3 199,955 1/24/2019
0.49.2 4,662,889 1/16/2019
0.49.0 9,215 1/12/2019
0.48.2 130,763 12/12/2018
0.48.1 9,373 12/10/2018
0.48.0 19,744 12/8/2018
0.47.1 3,305,511 11/4/2018
0.47.0 6,090 11/3/2018
0.46.2 18,536 10/25/2018
0.46.1 108,021 10/16/2018
0.46.0 13,620 10/12/2018
0.45.1 832,361 9/29/2018
0.45.0 33,251 9/13/2018
0.44.1 1,302,231 8/24/2018
0.44.0 10,236 8/21/2018
0.43.0 125,748 7/27/2018
0.42.3 50,442 7/6/2018
0.42.2 92,006 6/30/2018
0.42.1 995,666 6/16/2018
0.42.0 19,396 6/9/2018
0.41.0 6,318 6/8/2018
0.40.4 894,747 5/19/2018
0.40.3 70,829 4/26/2018
0.40.2 26,132 4/19/2018
0.36.0 49,475 2/16/2018
0.35.0 73,309 1/21/2018
0.32.0 1,012,329 11/24/2017
0.30.0 94,134 10/31/2017
0.29.4 27,139 10/31/2017
0.29.2 67,701 10/26/2017
0.26.5 33,309 9/22/2017
0.26.4 347,686 9/13/2017
0.26.3 5,204 9/13/2017
0.26.2 52,664 9/7/2017
0.26.1 30,051 9/3/2017
0.26.0 38,311 8/25/2017
0.25.1 102,149 8/17/2017
0.25.0 34,288 8/13/2017
0.20.0 6,652 6/1/2017
0.19.5 16,197 5/26/2017
0.19.4 6,733 5/13/2017
0.19.3 5,825 5/11/2017
0.19.2 2,575,772 5/1/2017
0.16.2 30,423 4/2/2017
0.10.0 13,826 12/29/2016
0.9.0 7,146 12/13/2016
0.8.0 8,159 12/7/2016
0.7.4 6,032 12/7/2016
0.7.3 63,027 11/28/2016
0.7.2 17,675 11/23/2016
0.7.1 10,549 11/21/2016
0.7.0 8,850 11/13/2016
0.6.2 28,151 10/28/2016
0.6.1 6,492 10/27/2016
0.6.0 6,096 10/23/2016
0.5.0 6,646 10/20/2016
0.4.0 7,668 10/13/2016
0.3.0 6,198 10/12/2016
0.2.1 5,938 10/10/2016
0.2.0 6,028 10/9/2016
0.1.0 21,037 10/4/2016