LangStop · MySQL · ERD Generator

MySQL ERD Generator — Visualize MySQL Schemas

Import SQL with the MySQL option to turn CREATE TABLE statements into an entity-relationship diagram. Paste the output of SHOW CREATE TABLE, a migration file, or a schema script with backtick-quoted names, and the tables, keys and foreign keys appear on the canvas as DBML.

The conversion runs in your browser through the MySQL grammar in @dbml/core. The app does not send the statements to a server.

How this tool handles it

  • Read: CREATE TABLE with column types, NOT NULL, DEFAULT, AUTO_INCREMENT, PRIMARY KEY, UNIQUE KEY, KEY (an index), ENUM(...), CONSTRAINT ... FOREIGN KEY ... REFERENCES ... ON DELETE, and an inline REFERENCES in a column definition.
  • Dropped: UNSIGNED, COLLATE, ENGINE= and DEFAULT CHARSET=.
  • Named keys: a UNIQUE KEY or KEY keeps its name. A PRIMARY KEY over several columns becomes a pk index on those columns.
  • Foreign keys: a CONSTRAINT name is kept on its Ref line. An inline REFERENCES has no name, so its Ref line has none either.

Worked example

This schema has an ENUM, an AUTO_INCREMENT key, a unique key, a plain key and a named foreign key:

CREATE TABLE `customers` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `email` varchar(255) NOT NULL,
  `plan` enum('free','pro') NOT NULL DEFAULT 'free',
  PRIMARY KEY (`id`),
  UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
CREATE TABLE `orders` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `customer_id` bigint unsigned NOT NULL,
  `total` decimal(10,2) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `customer_id` (`customer_id`),
  CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB;

The DBML that comes out:

Enum "customers_plan_enum" {
  "free"
  "pro"
}
 
Table "customers" {
  "id" bigint [pk, not null, increment]
  "email" varchar(255) [not null]
  "plan" customers_plan_enum [not null, default: 'free']
 
  Indexes {
    email [unique, name: "email"]
  }
}
 
Table "orders" {
  "id" bigint [pk, not null, increment]
  "customer_id" bigint [not null]
  "total" decimal(10,2) [not null]
 
  Indexes {
    customer_id [name: "customer_id"]
  }
}
 
Ref "orders_ibfk_1":"customers"."id" < "orders"."customer_id" [delete: cascade]

unsigned is gone from both id columns, and the ENGINE and CHARSET clauses do not appear.

Gotchas

1. UNSIGNED is lost. int unsigned NOT NULL becomes int [not null]. A diagram of an unsigned key looks the same as a signed one. Keep a note of the unsigned columns, or add it to the column name or note.

2. A CHECK constraint makes the DBML invalid. Input:

CREATE TABLE `t` (
  `id` int unsigned NOT NULL,
  `qty` int NOT NULL,
  `name` varchar(20) COLLATE utf8mb4_bin DEFAULT NULL,
  PRIMARY KEY (`id`),
  CONSTRAINT `qty_pos` CHECK (`qty` > 0)
) ENGINE=InnoDB;

The DBML that comes out:

Table "t" {
  "id" int [pk, not null]
  "qty" int [not null]
  "name" varchar(20) [default: NULL]
 
  Checks {
    ``qty` > 0` [name: 'qty_pos']
  }
}

The Checks block is rejected by the DBML parser, and the expression comes out with doubled backticks. Remove the CHECK before you import.

3. COLLATE is dropped. varchar(20) COLLATE utf8mb4_bin DEFAULT NULL becomes varchar(20) [default: NULL]. Collation is not shown, so compare collations in your DDL when they matter.

4. An inline REFERENCES is drawn as a relationship. item_order int NOT NULL REFERENCES items (order_id) is turned into an unnamed Ref line. MySQL accepts that clause but does not enforce it on InnoDB tables, so the line in the diagram may describe a relationship that the database does not enforce. The ALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY form keeps its name and is the one to use for real keys.

Frequently asked questions

Are MySQL ENUM columns imported?

Yes. An ENUM column becomes an Enum block named after the table and column, such as customers_plan_enum, and the column uses that type. The value list is kept in the same order as the DDL.

What happens to AUTO_INCREMENT?

A column with AUTO_INCREMENT is marked increment in the DBML, so the diagram shows it as an auto-increment key. The table engine and the default charset are not in the output.

Why is UNSIGNED missing from my column types?

The importer drops UNSIGNED, so bigint unsigned appears as bigint and int unsigned as int. Check the unsigned columns in your DDL, because the diagram does not show the difference.

Why does my MySQL import fail with a CHECK constraint?

A CHECK constraint is written as a Checks block, and the DBML parser rejects that block. The importer also doubles the backticks around the check expression. Remove CHECK clauses from the text before you import.