Package: dbt-mysql-adapter
dbt-mysql-adapterThis is a maintained fork of thedbt-mysqlproject.This plugin portsdbtfunctionality to MySQL.This is an experimental plugin:We have not tested it extensivelyStorage engines other than the default of InnoDB are untestedMariaDB compatibility is untestedOnly tested withdbt-adapter-testswith MySQL 5.6, 5.7, and 8.0Compatiblity with otherdbt packages(likedbt_utils) is also untestedPlease read these docs carefully and use at your own risk.IssuesandPRswelcome!Table of ContentsInstallationSupported featuresMySQL 8.0MySQL 5.6 and 5.7MySQL 5.6 configuration gotchasMySQL 5.7 configuration gotchasConfiguring your profileNotesRunning TestsReporting bugs and contributing codeInstallationThis plugin can be installed via pip:$pipinstalldbt-mysqlSupported features5.6 / 5.78.0Feature✅✅Table materialization✅✅View materialization✅✅Incremental materialization❌✅Ephemeral materialization✅✅Seeds✅✅Sources✅✅Custom data tests✅✅Docs generate🤷✅SnapshotsNotes:Ephemeral materializations rely uponCommon Table Expressions(CTEs), which are not supported until MySQL 8.0MySQL 5.6 and 5.7 have some configuration gotchas that affect snapshots (see below).MySQL 5.6 configuration gotchasdbt snapshots might not work properly due toautomatic initialization and updating forTIMESTAMPif:the output ofSHOW VARIABLES LIKE 'sql_mode'includesNO_ZERO_DATEthe output ofSHOW GLOBAL VARIABLES LIKE 'explicit_defaults_for_timestamp'has a value ofOFFA solution is to include the following in a*.cnffile:
Configuration to include in a*.cnffile:[mysqld]
explicit_defaults_for_timestamp = trueMySQL 5.7 configuration gotchasdbt snapshots might not work properly due toautomatic initialization and updating forTIMESTAMPif:
dbt snapshots might not work properly if:the output ofSHOW VARIABLES LIKE 'sql_mode'includesNO_ZERO_DATEA solution is to include the following in a*.cnffile:
Configuration to include in a*.cnffile:[mysqld]
explicit_defaults_for_timestamp = true
sql_mode = "ALLOW_INVALID_DATES,{other_sql_modes}"where{other_sql_modes}is the rest of the modes from theSHOW VARIABLES LIKE 'sql_mode'output.Configuring your profileA dbt profile can be configured to run against MySQL using the following configuration example:Usetype: mysqlfor MySQL 8.x andtype: mysql5for MySQL 5.xExample entry for profiles.yml:your_profile_name:
  target: dev
  outputs:
    dev:
      type: mysql
      server: localhost
      port: 3306
      schema: analytics
      username: your_mysql_username
      password: your_mysql_passwordOptionDescriptionRequired?ExampletypeThe specific adapter to useRequiredmysqlormysql5serverThe server (hostname) to connect toRequiredyourorg.mysqlhost.comportThe port to useOptional3306schemaSpecify the schema (database) to build models intoRequiredanalyticsusernameThe username to use to connect to the serverRequireddbt_adminpasswordThe password to use for authenticating to the serverRequiredcorrect-horse-battery-stapleNotesConflicting terminology is used between:dbtDatabase management systems (DBMS) like MySQL, Postgres, and Snowflakemetadata in the ANSI-standardinformation_schemaThe conflicts include both:the same word meaning different thingsdifferent words meaning the same thingFor example, a "database" in MySQL is not the same as a "database" in dbt, but it is equivalent to a "schema" in Postgres 🤯.dbt-mysql-adapter uses the dbt terms. The native MySQL verbiage is restricted to SQL statements.This cross-walk aligns the terminology:information_schemadbt (and Postgres)MySQLcatalogdatabaseundefined / not implementedschemaschemadatabaserelation (table/view)relation (table/view)relation (table/view)columncolumncolumnAdditionally, many DBMS have relation names with three parts whereas MySQL has only two. E.g., a fully-qualified table name in Postgres isdatabase.schema.tableversusdatabase.tablein MySQL. The missing part in MySQL is theinformation_schema"catalog".DBMSFully-qualified relation namePartsPostgresdatabase.schema.table3MySQLdatabase.table2Running TestsSeetest/README.mdfor details on running the integration tests.Reporting bugs and contributing codeWant to report a bug or request a feature? See thecontributing guidelines, or openan issue.Creditsdbt-mysql-adapter borrows fromdbt-sparkanddbt-sqlitesince Spark and SQLite also use two-part relation names.