MySqlConnector
2.6.1
39 download(s)
public
A truly async MySQL ADO.NET provider, supporting MySQL Server, MariaDB, Amazon Aurora, Azure Database for MySQL, Google Cloud SQL, and more.
mysql
mysqlconnector
async
ado.net
database
netcore
PackageReference
<PackageReference Include="MySqlConnector" Version="2.6.1" />
.NET CLI
dotnet add package MySqlConnector --version 2.6.1
Dependencies
net10.0
| Package | Version range |
|---|---|
| Microsoft.Extensions.DependencyInjection.Abstractions | [8.0.2, ) |
| Microsoft.Extensions.Logging.Abstractions | [8.0.2, ) |
net462
| Package | Version range |
|---|---|
| Microsoft.Extensions.DependencyInjection.Abstractions | [8.0.2, ) |
| Microsoft.Extensions.Logging.Abstractions | [8.0.2, ) |
| System.Diagnostics.DiagnosticSource | [8.0.1, ) |
| System.Threading.Tasks.Extensions | [4.6.3, ) |
net471
| Package | Version range |
|---|---|
| Microsoft.Extensions.DependencyInjection.Abstractions | [8.0.2, ) |
| Microsoft.Extensions.Logging.Abstractions | [8.0.2, ) |
| System.Diagnostics.DiagnosticSource | [8.0.1, ) |
| System.Threading.Tasks.Extensions | [4.6.3, ) |
net48
| Package | Version range |
|---|---|
| Microsoft.Extensions.DependencyInjection.Abstractions | [8.0.2, ) |
| Microsoft.Extensions.Logging.Abstractions | [8.0.2, ) |
| System.Diagnostics.DiagnosticSource | [8.0.1, ) |
| System.Threading.Tasks.Extensions | [4.6.3, ) |
net6.0
| Package | Version range |
|---|---|
| Microsoft.Extensions.DependencyInjection.Abstractions | [8.0.2, ) |
| Microsoft.Extensions.Logging.Abstractions | [8.0.2, ) |
| System.Diagnostics.DiagnosticSource | [8.0.1, ) |
net8.0
| Package | Version range |
|---|---|
| Microsoft.Extensions.DependencyInjection.Abstractions | [8.0.2, ) |
| Microsoft.Extensions.Logging.Abstractions | [8.0.2, ) |
net9.0
| Package | Version range |
|---|---|
| Microsoft.Extensions.DependencyInjection.Abstractions | [8.0.2, ) |
| Microsoft.Extensions.Logging.Abstractions | [8.0.2, ) |
netstandard2.0
| Package | Version range |
|---|---|
| Microsoft.Extensions.DependencyInjection.Abstractions | [8.0.2, ) |
| Microsoft.Extensions.Logging.Abstractions | [8.0.2, ) |
| System.Diagnostics.DiagnosticSource | [8.0.1, ) |
| System.Threading.Tasks.Extensions | [4.6.3, ) |
netstandard2.1
| Package | Version range |
|---|---|
| Microsoft.Extensions.DependencyInjection.Abstractions | [8.0.2, ) |
| Microsoft.Extensions.Logging.Abstractions | [8.0.2, ) |
| System.Diagnostics.DiagnosticSource | [8.0.1, ) |
Readme
## About
MySqlConnector is a C# [ADO.NET](https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/) driver for [MySQL](https://www.mysql.com/), [MariaDB](https://mariadb.org/), [Amazon Aurora](https://aws.amazon.com/rds/aurora/), [Azure Database for MySQL](https://azure.microsoft.com/en-us/services/mysql/) and other MySQL-compatible databases.
More documentation is available at the [MySqlConnector website](https://mysqlconnector.net/).
## How to Use
```csharp
// 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
await using var connection = new MySqlConnection(builder.ConnectionString);
await connection.OpenAsync();
// create a DB command and set the SQL statement with parameters
await 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
await using var reader = await command.ExecuteReaderAsync();
while (reader.Read())
{
var id = reader.GetInt32("order_id");
var date = reader.GetDateTime("order_date");
// ...
}
```
### ASP.NET Core
For ASP.NET Core, `MySqlConnector` includes `AddMySqlDataSource` to integrate with dependency injection and logging.
```csharp
using MySqlConnector;
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
* Entity Framework Core: [Pomelo.EntityFrameworkCore.MySql](https://www.nuget.org/packages/Pomelo.EntityFrameworkCore.MySql/)
## Feedback
MySqlConnector is released as open source under the [MIT license](https://github.com/mysql-net/MySqlConnector/blob/master/LICENSE). Bug reports and contributions are welcome at [the GitHub repository](https://github.com/mysql-net/MySqlConnector).
Versions
Target frameworks
net10.0
net462
net471
net48
net6.0
net8.0
net9.0
netstandard2.0
netstandard2.1
Metadata
- Published
- Size
- 3.65 MB
- Authors
- Bradley Grainger
- License
- MIT
- Project
- https://mysqlconnector.net/
- Repository
- https://github.com/mysql-net/MySqlConnector.git commit 5802bd06d4e0787215b9f7acc4c8f8cf4ee8de8a
- Flags
- SemVer 1
- SHA512
- CUytMvzWgWbLjbATO1b/XB/lVG1OZIRqhv36Rmk5wIDE1A0vnh6B3JMOB/HfMkJLmIMHdL1ssfeCiPmr7IGYtQ==
Release notes
https://mysqlconnector.net/overview/version-history/