LinkMenuExpand(external link)DocumentSearchCopyCopied

MySqlConnector: High Performance .NET MySQL Driver

About

MySqlConnector is a C# ADO.NET driver for MySQL Server, MariaDB, Amazon Aurora, Azure Database for MySQL, Google Cloud SQL for MySQL, Percona Server and more. It provides implementations of DbConnection, DbCommand, DbDataReader, DbTransaction — the classes needed to query and update databases from C# code.

Getting Started

Install MySqlConnector from NuGet: dotnet add package MySqlConnector

Connecting to your database is simple. For example, in C#:

using var connection = new MySqlConnection("Server=myserver;User ID=mylogin;Password=mypass;Database=mydatabase");
connection.Open();

using var command = new MySqlCommand("SELECT field FROM table;", connection);
using var reader = command.ExecuteReader();
while (reader.Read())
    Console.WriteLine(reader.GetString(0));

For more information, see how to install and a basic example of using the API. Many ORMs are supported.

Asynchronous I/O

MySqlConnector also fully supports asynchronous I/O. The C# example above can be rewritten as:

await using var connection = new MySqlConnection("Server=myserver;User ID=mylogin;Password=mypass;Database=mydatabase");
await connection.OpenAsync();

using var command = new MySqlCommand("SELECT field FROM table;", connection);
await using var reader = await command.ExecuteReaderAsync();
while (await reader.ReadAsync())
    Console.WriteLine(reader.GetString(0));

Server Compatibility

MySqlConnector is compatible with the following servers. Version numbers in bold indicate versions that are regularly tested by the integration tests run on every commit.

ServerVersionsNotes
Amazon Aurora RDS2.x, 3.xUse Pipelining=False for Aurora 2.x
Azure Database for MySQL5.7, 8.0Single Server and Flexible Server
Google Cloud SQL for MySQL5.6, 5.7, 8.0
MariaDB10.x (10.6, 10.11), 11.x (11.4)
MySQL5.5, 5.6, 5.7, 8.x (8.0, 8.4), 9.x (9.1)5.5 is EOL and has some compatibility issues; 5.6 and 5.7 are EOL
Percona Server5.6, 5.7, 8.0
PlanetScaleSee PlanetScale MySQL compatibility notes
ProxySQL2.xSome compatibility issues
SingleStoreDB
TiDB

Performance

MySqlConnector outperforms Connector/NET (MySql.Data) on benchmarks:

Benchmark results for MySql.Data vs MySqlConnector

(Client: MySqlConnector 2.3.1, MySql.Data 8.2.0, Ubuntu 23.04, .NET 8.0; Server: Azure Database for MySQL 8.0.34, TLS 1.2)

Why use MySqlConnector over Oracle’s MySQL Connector/NET?

MySqlConnector is a clean-room reimplementation of the MySQL Protocol and is not based on Oracle’s MySQL Connector/NET.

See MySqlConnector vs MySql.Data for reasons to switch to MySqlConnector and details on migrating.