Skip to main content

MySQL Reference

Authentication options and data type handling for MySQL connections.

Server​

servers:
- server: mysql
type: mysql
host: localhost
port: 3306
database: mydb

Authentication​

VariableExampleDescription
DATACONTRACT_MYSQL_USERNAMErootUsername
DATACONTRACT_MYSQL_PASSWORDmysecretpasswordPassword

host, port (default 3306), and database come from the contract's servers block, and can be overridden with DATACONTRACT_MYSQL_HOST, DATACONTRACT_MYSQL_PORT, and DATACONTRACT_MYSQL_DATABASE.

Data types​

Importing​

datacontract import sql --dialect mysql maps DDL types as follows; the normalized SQL type is kept as physicalType.

MySQL typelogicalType
VARCHAR, CHAR, TEXTstring (maxLength for varchar/char)
INT, INTEGER, BIGINT, SMALLINTinteger
NUMERIC, DECIMAL, FLOAT, DOUBLEnumber
BOOLEANboolean
DATEdate
TIMEtime
DATETIME, TIMESTAMPtimestamp
BLOB, BINARY, VARBINARYstring (format binary)
JSONobject
ENUM(...), YEAR, TINYINT(1), INT UNSIGNED(unset) — physicalType is still written

Testing​

MySQL is reached through DuckDB's MySQL scanner and does not support native type introspection — the declared physicalType is not compared against the catalog. Instead, the logicalType is checked by category (Check that field x has type y), with integer and number treated as compatible.

Logical type mapping​

When no physicalType is declared, the CLI derives the native type from the logicalType — for example in datacontract export sql and the dbt exports. This table is generated from the converter in the CLI's code:

logicalTypeMySQL type
stringvarchar(255)
integerint
numberdecimal
booleanboolean
datedate
timestamptimestamp
timetime
objectjson
arrayjson
mapjson
vectorvector(1536)