GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Data Contract CLI
  • Join Community
  • Quickstart
  • Open Data Contract Standard
  • Installation
  • Test your Data
  • Amazon Athena
  • Amazon Redshift
  • Amazon S3
  • Amazon S3 Tables
  • Apache Hive
  • Apache Iceberg
  • Apache Impala
  • Azure Blob / ADLS

This view

  • Original page
  • New address

GeezerVison is showing cli.datacontract.com — MySQL | Data Contract CLI

Test data in MySQL or MySQL-compatible databases (e.g. MariaDB).

1. Install​

uv tool install --python python3.11 --upgrade 'datacontract-cli[mysql]'

See Installation for pip, pipx, and Docker.

2. Authenticate​

Create a .env file in your working directory (or export the variables):

# .env
DATACONTRACT_MYSQL_USERNAME=root
DATACONTRACT_MYSQL_PASSWORD=mysecretpassword

3. Create a contract from your tables​

Import the table metadata directly from the database. This also generates a ready-to-test servers block:

datacontract import mysql \
--source localhost \
--database mydb \
--table orders \
--output datacontract.yaml

--source is the host of your MySQL server. Add --port if it doesn't listen on the default 3306, repeat --table for multiple tables, or omit it to import every table in the database.

Only have a DDL file? datacontract import sql --source orders.sql --dialect mysql works too, but writes a servers block with placeholder values that you have to fill in by hand.

4. Test the actual data​

datacontract test datacontract.yaml
Testing datacontract.yaml
Server: mysql (type=mysql, host=localhost, port=3306, database=mydb)
╭────────┬───────────────────────────────────────────┬──────────┬─────────╮
│ Result │ Check │ Field │ Details │
├────────┼───────────────────────────────────────────┼──────────┼─────────┤
│ ... │ │ │ │
│ passed │ Check that field 'order_id' is present │ order_id │ │
│ passed │ Check that field order_id has type string │ order_id │ │
│ ... │ │ │ │
╰────────┴───────────────────────────────────────────┴──────────┴─────────╯
🟢 Data contract is valid. Ran 24 checks. Took 2.1 seconds.

5. Let it catch a violation​

The contract becomes valuable when it detects drift. Tighten an expectation — for example, add a quality rule to a schema in datacontract.yaml:

schema:
- name: orders
# ...
quality:
- type: sql
description: No order has a negative total
query: SELECT COUNT(*) FROM orders WHERE order_total < 0
mustBe: 0

The tables are copied into DuckDB before the checks run, so write the query in DuckDB SQL, not MySQL.

Run datacontract test datacontract.yaml again: every violation is listed as an error, and the command exits with code 1 — ready for CI/CD and scheduled runs so you catch drift before your consumers do.

Metadata checks​

Instead of the data, you can check what MySQL records about it. Point a server at the catalog (database: information_schema); its schemas then name the catalog views, and every check works on them as on a table:

servers:
- server: catalog
type: mysql
host: localhost
port: 3306
database: information_schema
schema:
- name: TABLES
quality:
- type: sql
description: Every table in the shop database uses InnoDB
query: SELECT COUNT(*) FROM TABLES WHERE TABLE_SCHEMA = 'shop' AND ENGINE <> 'InnoDB'
mustBe: 0
properties:
- name: TABLE_NAME
logicalType: string
required: true
- name: TABLE_ROWS
logicalType: integer
logicalTypeOptions:
maximum: 100000000

Reference​

All authentication options and the data type mappings: MySQL Reference.

Troubleshooting​

  • Access denied for user — check the two environment variables above and the user's host restrictions ('user'@'%' vs 'user'@'localhost').
  • Can't connect to MySQL server — host/port in the servers block are wrong, or the server doesn't accept remote connections (bind-address).
  • 1. Install
  • 2. Authenticate
  • 3. Create a contract from your tables
  • 4. Test the actual data
  • 5. Let it catch a violation
  • Metadata checks
  • Reference
  • Troubleshooting
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.