Package: dbt-mysql
dbt-mysqlThis plugin portsdbtfunctionality to MySQL and MariaDB.This is an experimental plugin:We have not tested it extensivelyStorage engines other than the default of InnoDB are untestedOnly tested withdbt-tests-adapterwith the following:MySQL 5.7MySQL 8.0MariaDB 10.5Compatiblity with otherdbt packages(likedbt_utils) is also untestedSupported Python Versions are: 3.6, 3.7, 3.8 & 3.9Please read these docs carefully and use at your own risk.IssuesandPRswelcome!Table of ContentsInstallationSupported featuresMySQL 5.7 configuration gotchasConfiguring your profileNotesRunning TestsReporting bugs and contributing codeInstallationThis plugin can be installed via pip:$python-mpipinstalldbt-mysqlSupported featuresMariaDB 10.5MySQL 5.7MySQL 8.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.7 has some configuration gotchas that affect snapshots (see below).MySQL 5.7 configuration gotchasdbt snapshots might not work properly due toautomatic initialization and updating forTIMESTAMPif:the output ofSHOW VARIABLES LIKE 'sql_mode'includesNO_ZERO_DATEA solution is to include the following 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 configuration example below.Usetype: mysqlfor MySQL 8.x,type: mysql5for MySQL 5.x, andtype: mariadbfor MariaDB.Example 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_password
      ssl_disabled: TrueOptionDescriptionRequired?ExampletypeThe specific adapter to useRequiredmysql,mysql5ormariadbserverThe 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-staplessl_disabledSet to enable or disable TLS connectivity to mysql5.xOptionalTrueorFalseNotesConflicting 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 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 borrows fromdbt-sparkanddbt-sqlitesince Spark and SQLite also use two-part relation names.