|
| 1 | +# MySqlConnector |
| 2 | + |
| 3 | +## About |
| 4 | + |
| 5 | +MySqlConnector is an [ADO.NET](https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/) data provider 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. It provides implementations of `DbConnection`, `DbCommand`, `DbDataReader`, `DbTransaction`—the classes needed to query and update databases from managed code. |
| 6 | + |
| 7 | +Complete documentation is available at the [MySqlConnector Documentation Website](https://mysqlconnector.net/). |
| 8 | + |
| 9 | +## How to Use |
| 10 | + |
| 11 | +```csharp |
| 12 | +// set these values correctly for your database server |
| 13 | +var builder = new MySqlConnectionStringBuilder |
| 14 | +{ |
| 15 | + Server = "your-server", |
| 16 | + UserID = "database-user", |
| 17 | + Password = "P@ssw0rd!", |
| 18 | + Database = "database-name", |
| 19 | +}; |
| 20 | + |
| 21 | +// open a connection asynchronously |
| 22 | +using var connection = new MySqlConnection(builder.ConnectionString); |
| 23 | +await connection.OpenAsync(); |
| 24 | + |
| 25 | +// create a DB command and set the SQL statement with parameters |
| 26 | +using var command = connection.CreateCommand(); |
| 27 | +command.CommandText = @"SELECT * FROM orders WHERE order_id = @OrderId;"; |
| 28 | +command.Parameters.AddWithValue("@OrderId", orderId); |
| 29 | + |
| 30 | +// execute the command and read the results |
| 31 | +using var reader = await command.ExecuteReaderAsync(); |
| 32 | +while (reader.Read()) |
| 33 | +{ |
| 34 | + var id = reader.GetInt32("order_id"); |
| 35 | + var date = reader.GetDateTime("order_date"); |
| 36 | + // ... |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +## Key Features |
| 41 | + |
| 42 | +* Full support for async I/O |
| 43 | +* High performance |
| 44 | +* Supports. NET Framework, .NET Core, and .NET 5.0+ |
| 45 | + |
| 46 | +## Related Packages |
| 47 | + |
| 48 | +* Entity Framework Core: [Pomelo.EntityFrameworkCore.MySql](https://www.nuget.org/packages/Pomelo.EntityFrameworkCore.MySql/) |
| 49 | +* Logging: [log4net](https://www.nuget.org/packages/MySqlConnector.Logging.log4net/), [Microsoft.Extensions](https://www.nuget.org/packages/MySqlConnector.Logging.Microsoft.Extensions.Logging/), [NLog](https://www.nuget.org/packages/MySqlConnector.Logging.NLog/), [Serilog](https://www.nuget.org/packages/MySqlConnector.Logging.Serilog/) |
| 50 | + |
| 51 | +## Feedback |
| 52 | + |
| 53 | +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). |
0 commit comments