MSSQL to MySQL migration tool with data, primary key and foreign key support
Project description
mssql2mysql
A config-driven CLI tool to migrate Microsoft SQL Server databases to MySQL. Handles data, primary keys, and foreign keys with batch processing and progress tracking.
Features
- Data migration — Copies all tables and rows with configurable batch size
- Schema inference — Builds MySQL tables from MSSQL metadata with automatic type mapping
- Primary keys — Migrates PK constraints from MSSQL to MySQL
- Foreign keys — Migrates FK constraints with strict or smart mode
- Progress tracking — Per-table progress bars and row counts
- YAML config — Single config file for both source and target
Requirements
- Python 3.9+
- SQL Server ODBC Driver (e.g. ODBC Driver 18 for SQL Server)
- MySQL Server (target)
Installation
pip install mssql2mysql
Or from source:
git clone https://github.com/mananpatel08/mssql2mysql.git
cd mssql2mysql
pip install -e .
Quick Start
-
Create a config file
mssql2mysql --initThis creates
migration.yamlin the current directory. -
Edit the config with your MSSQL and MySQL connection details.
-
Run the migration
mssql2mysql --config migration.yaml
Configuration
Example migration.yaml (from --init):
mssql:
server: localhost
port: 1433
database: your_database
user: sa
password: your_password
mysql:
host: localhost
database: your_database
user: root
password: your_password
mode: strict # strict | smart
batch_size: 1000
| Option | Description |
|---|---|
mssql.server |
MSSQL host |
mssql.port |
MSSQL port (default 1433) |
mssql.database |
Source database name |
mssql.user / mssql.password |
MSSQL credentials |
mysql.host |
MySQL host |
mysql.database |
Target database name |
mysql.user / mysql.password |
MySQL credentials |
mode |
strict (default): stop on first FK error. smart: create indexes on referenced columns if needed, continue on FK errors. |
batch_size |
Rows per insert batch (default 1000) |
CLI Reference
| Command | Description |
|---|---|
mssql2mysql --init |
Create a sample migration.yaml in the current directory. |
mssql2mysql --config <file> |
Run migration using the given YAML config file. |
Migration Modes
- strict (default) — Stops the entire migration if any foreign key fails to be added. Use when you want a fully consistent schema.
- smart — Before adding each FK, ensures the referenced column has an index (creates one if missing). On FK add failure, logs the error and continues with the rest. Use when some FKs may be invalid or you prefer best-effort migration.
Type Mapping
MSSQL types are mapped to MySQL as follows (among others):
| MSSQL | MySQL |
|---|---|
varchar / nvarchar / char / nchar |
VARCHAR(n) or LONGTEXT (max) |
decimal / numeric |
DECIMAL(p,s) |
datetime / datetime2 |
DATETIME |
date |
DATE |
int |
INT |
bigint |
BIGINT |
bit |
TINYINT(1) |
varbinary / binary / image |
BLOB / LONGBLOB |
Unsupported types fall back to TEXT. Nullability is preserved.
How It Works
- Data — Connects to MSSQL and MySQL, reads table list and column metadata, creates MySQL tables with mapped types, then batch-inserts rows with progress output. Foreign key checks are disabled during data load.
- Primary keys — Reads PK definitions from MSSQL
INFORMATION_SCHEMA, adds them in MySQL (skips if already present). - Foreign keys — Reads FK definitions from MSSQL system tables, adds them in MySQL (in smart mode, creates indexes on referenced columns as needed).
Links
- Repository: github.com/mananpatel08/mssql2mysql
- Issues: github.com/mananpatel08/mssql2mysql/issues
License
MIT © Manan Patel
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mssql2mysql-0.1.1.tar.gz.
File metadata
- Download URL: mssql2mysql-0.1.1.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
748287099ae017956ad4b65c6ea35ca9371256efb34668abd9ce379cf92bbb8d
|
|
| MD5 |
824ee17204f4a8b2238d25b84c559e37
|
|
| BLAKE2b-256 |
c24459566c9b8480d2ed5b615398805ef18ce935e6c965e0015624aedae814c8
|
File details
Details for the file mssql2mysql-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mssql2mysql-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07196b4a3d81438c189a72da2d432d3ad7b2eadead6dd15cfadf7c090619d2b0
|
|
| MD5 |
bbc815de107ee830562a4bac5e7f7d8d
|
|
| BLAKE2b-256 |
ab1486ef3369646a8e0f945112acc43e0ae17788dad1c173ff6627583d36df1b
|