Skip to main content

MySQL

note

The Synth MySQL integration is currently in beta.

Usage#

synth can use MySQL as a data source or sink. Connecting synth to a MySQL is as simple as specifying a URI and schema during the import or generate phase.

URI format#

mysql://<username>:<password>@<host>:<port>/<catalog>

One quirk with the current MySQL integration is that the host can't be represented in IPv4, so DNS or IPv6 representations should be used instead. If IPv4 compatibility is wanted, use IPv4-mapped IPv6.

Import#

synth can import directly from a MySQL database and create a data model from the database schema. During import, a new namespace will be created from your database schema, and a collection is created for each table in a separate JSON file. synth will map database columns to fields in the collections it creates. It then provides default generators for every collection. Synth will default to the public schema but this can be overriden with the --schema flag.

synth will automatically detect primary key and foreign key constraints at import time and update the namespace and collection to reflect them. Primary keys get mapped to synth's id generator, and foreign keys get mapped to the same_as generator.

Finally synth will sample data randomly from every table in order to create a more realistic data model by automatically inferring bounds on types.

synth has its own internal data model, and so does MySQL, therefore a conversion occurs between synth types and MySQL types. The inferred type can be seen below. The synth types link to default generator variant generated during the import process for that PostgreSQL type.

Note, not all MySQL types have been covered yet. If there is a type you need, open an issue on GitHub.

MySQL TypeSynth Type
charstring
varchar(x)string
textstring
enumstring
inti32
integeri32
tinyinti8
biginti64
serialu64
floatf32
doublef64
numericf64
decimalf64
timestampdate_time
datetimenaive_date_time
datenaive_date
timenaive_time
### Example Import Command
```bashsynth import --from mysql://user:pass@localhost:5432/postgres --schemamain my_namespace

Example#

Generate#

synth can generate data directly into your MySQL database. First synth will generate as much data as required, then open a connection to your database, and then perform batch insert to quickly insert as much data as you need.

synth will also respect primary key and foreign key constraints, by performing a topological sort on the data and inserting it in the right order such that no constraints are violated.

Example Generation Command#

synth generate --to mysql://user:pass@localhost:5432/ --schemamain my_namespace