MySqlConnector 2.3.7
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 ofDbConnection)MySqlCommand(implementation ofDbCommand)MySqlDataReader(implementation ofDbDataReader)MySqlBulkCopyMySqlBulkLoaderMySqlConnectionStringBuilderMySqlConnectorFactoryMySqlDataAdapterMySqlExceptionMySqlTransaction(implementation ofDbTransaction)
Related Packages
- Dependency Injection: MySqlConnector.DependencyInjection
- Entity Framework Core: Pomelo.EntityFrameworkCore.MySql
Feedback
MySqlConnector is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.
No packages depend on MySqlConnector.
https://mysqlconnector.net/overview/version-history/
.NET Framework 4.6.2
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
- System.Threading.Tasks.Extensions (>= 4.5.4)
- System.Diagnostics.DiagnosticSource (>= 7.0.2)
.NET Standard 2.1
- System.Diagnostics.DiagnosticSource (>= 7.0.2)
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
.NET Standard 2.0
- System.Threading.Tasks.Extensions (>= 4.5.4)
- System.Diagnostics.DiagnosticSource (>= 7.0.2)
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
.NET 8.0
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
.NET 7.0
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
.NET 6.0
- System.Diagnostics.DiagnosticSource (>= 7.0.2)
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
.NET Framework 4.8
- System.Diagnostics.DiagnosticSource (>= 7.0.2)
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
- System.Threading.Tasks.Extensions (>= 4.5.4)
.NET Framework 4.7.1
- System.Threading.Tasks.Extensions (>= 4.5.4)
- System.Diagnostics.DiagnosticSource (>= 7.0.2)
- Microsoft.Extensions.Logging.Abstractions (>= 7.0.1)
| Version | Downloads | Last updated |
|---|---|---|
| 2.3.7 | 15 | 08/17/2024 |