Skip to content

MySQL Overview

Weasel.MySql provides schema management and migration support for MySQL databases using the MySqlConnector driver.

Installation

bash
dotnet add package Weasel.MySql

Key Components

  • MySqlProvider -- Singleton at MySqlProvider.Instance that handles type mappings and identifier parsing. The default schema is public.
  • MySqlMigrator -- Generates DDL scripts and executes schema migrations. Identifiers are quoted with backticks.

Supported Schema Objects

ObjectClassNamespace
TablesTableWeasel.MySql.Tables
SequencesSequenceWeasel.MySql

Connection String

Weasel.MySql uses standard MySQL connection strings compatible with MySqlConnector:

cs
var connectionString = "Server=localhost;Database=mydb;User=root;Password=YourPassword;";

snippet source | anchor

Type Mappings

.NET TypeMySQL Type
stringVARCHAR(255)
intINT
longBIGINT
boolTINYINT(1)
decimalDECIMAL(18,2)
doubleDOUBLE
DateTimeDATETIME
GuidCHAR(36)
byte[]BLOB

Creating a Migrator

cs
var migrator = new MySqlMigrator();

snippet source | anchor

The migrator can ensure the target database exists:

cs
await using var conn = new MySqlConnection(connectionString);
await migrator.EnsureDatabaseExistsAsync(conn);
// Generates: CREATE DATABASE IF NOT EXISTS `mydb`;

snippet source | anchor

Released under the MIT License.