How to make a MySQL ER diagram
- 1Run mysqldump --no-data --skip-triggers mydb > schema.sql, or copy SHOW CREATE TABLE output.
- 2Keep MySQL selected and paste the SQL into the editor.
- 3Check the foreign key lines, primary keys and ENUM columns.
- 4Drag tables or re-run auto-layout to arrange the diagram.
- 5Export PNG or SVG, or MySQL, PostgreSQL or SQL Server SQL, DBML or Mermaid.
Getting your MySQL schema
mysqldump --no-data mydb > schema.sql writes every CREATE TABLE without rows; add --skip-triggers to leave out triggers. For a few tables, run SHOW CREATE TABLE table_name in any client and paste the result. In MySQL Workbench, Server > Data Export with Dump Structure Only produces the same kind of file.
The /*!40101 ... */ lines at the top of a dump are MySQL version comments. If any statement there or a stored procedure stops the parser, delete it and keep the CREATE TABLE statements.
Why foreign key lines can be missing in MySQL
Only InnoDB tables enforce foreign keys. Tables created with ENGINE=MyISAM, and schemas from frameworks that skip constraints, have columns like customer_id but no FOREIGN KEY clause, so there is nothing to draw a line from.
To document the intended relationships anyway, convert the SQL to DBML and add Ref lines such as Ref: orders.customer_id > customers.id. Exporting that DBML back to MySQL SQL then writes proper FOREIGN KEY constraints you can review and apply.
Naming conventions for tables and keys
Pick one style and keep it: lowercase snake_case works in every database without quoting, because PostgreSQL folds unquoted names to lowercase and MySQL table names can be case-sensitive on Linux. Decide once whether table names are plural (users) or singular (user).
Name foreign keys after the table they point at plus _id, such as user_id or order_id, so relationships are obvious even without the diagram. Avoid reserved words like user, order and group as table names; they work only when quoted, which is easy to forget in queries.
Use consistent suffixes for common columns: created_at and updated_at for timestamps, is_ or has_ prefixes for booleans, and the same type for a key and every foreign key that references it, for example bigint on both sides.