MySQL
note
The Synth MySQL integration is currently in beta.
#
Usagesynth
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 formatmysql://<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.
#
Importsynth
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 Type | Synth Type |
---|---|
char | string |
varchar(x) | string |
text | string |
enum | string |
int | i32 |
integer | i32 |
tinyint | i8 |
bigint | i64 |
serial | u64 |
float | f32 |
double | f64 |
numeric | f64 |
decimal | f64 |
timestamp | date_time |
datetime | naive_date_time |
date | naive_date |
time | naive_time |
### Example Import Command
```bashsynth import --from mysql://user:pass@localhost:5432/postgres --schemamain my_namespace
#
Example#
Generatesynth
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 Commandsynth generate --to mysql://user:pass@localhost:5432/ --schemamain my_namespace