Skip to main content
.NETFramework4.6.2.NETFramework4.7.1.NETFramework4.8net6.0net7.0net8.0

A truly async MySQL ADO.NET provider, supporting MySQL Server, MariaDB, Amazon Aurora, Azure Database for MySQL, Google Cloud SQL, and more.

Published
Mar 20, 2024
2y ago
Total Downloads
261.9M
261,855,508

Install

dotnet add package MySqlConnector --version 2.3.6
ProductVersions
.NET
net6.0net7.0net8.0
.NET Standard
netstandard2.0netstandard2.1
Other
.NETFramework4.6.2.NETFramework4.7.1.NETFramework4.8

README

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)

Related Packages

Feedback

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

Changes from Previous Version

No structural changes between v2.3.5 and v2.3.6.

Adoption Assessment

Services requiring reliable async behavior and modern .NET compatibility with MySQL-family databases.

Databases Guide
Compatibility metadata lists 8 target frameworks; confirm the exact target used by your application.The published metadata declares 18 direct dependency entries across framework groups. Inspect the resolved dependency graph for your target framework.
Editorial Note: Fully managed async-first MySQL connector widely used for MySQL and MariaDB workloads. Trade-off: Engine-version and server-configuration differences still require integration testing in realistic environments.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.