Skip to main content

MySQL

Preparation

To allow Shaped to connect to your MySQL database, you need to create a read-only user and share those credentials through the Create Dataset endpoint. You can create a read-only user on a MySQL database with the following commands:

# 1. Create a new user. 
CREATE USER '[username]'@'%' IDENTIFIED BY '[password]';

# 2. Grant the user read access to all the tables in the schema. Note you can also
# restrict this to your specific user, item and interaction views.
GRANT SELECT ON [database_name].* TO '[username]'@'%';

# 3. Save.
FLUSH PRIVILEGES;

Dataset Configuration

Required fields

FieldExampleDescription
schema_typeMYSQLSpecifies the connector schema type, in this case "MYSQL".
tablemoviesThe name of the table to sync.
useryour_userAccess account username.
passwordpAssw0rd1!Access account Password.
hostmy-mysql-db.xxxxxxx.us-east-2.rds.amazonaws.comDatabase hostname.
port3306Database port (the default for MySQL is 3306).
databasemovielensThe name of the database that contains table to sync.
replication_keyupdated_atThe name of the column that contains a datetime key or ascending id for ordering data during incremental syncs.

Optional fields

FieldExampleDescription
columns["productId", "color", "brand", "stockLevel"]The name of the columns you wish to sync from MySQL into Shaped. If not specified, all columns will be synced.
unique_keys["productId"]Specify a list of columns that uniquely identify a row in the table, if duplicate rows are inserted with these keys, the latest row will be used.

Dataset Creation Example

Below is an example of a MySQL dataset connector configuration:

name: your_mysql_dataset
schema_type: MYSQL
table: movies
user: your_user
password: pAssw0rd1!
host: my-mysql-db.xxxxxxx.us-east-2.rds.amazonaws.com
port: 3306
database: movielens
replication_key: updated_at

The following payload will create a MySQL dataset and begin syncing data from Shaped using the Shaped CLI.

shaped create-dataset --file dataset.yaml