While reworking our initial code completion implementation in MySQL Workbench I developed an approach that can potentially be applied for many different situations/languages where you need code completion. The current implementation is made for the needs of MySQL Workbench, but with some small refactorings you can move out the MySQL specific parts and have a clean core implementation that you can easily customize to your needs.

Since this implementation is not only bound to MySQL Workbench I posted the full description on my private blog.

This artcle will show you how to create a diagram for existing MySQL or MariaDB database using MySQL Workbench.

Reverse engineer a database

  • MySQL Workbench enables a DBA, developer, or data architect to visually design, model, generate, and manage databases. It includes everything a data modeler needs for creating complex ER models, forward and reverse engineering, and also delivers key features for performing difficult change management and documentation tasks that normally require much time and effort.
  • How to Import CSV file in MySQL Table by using MySQL Workbench demo explains all the steps you need to take to import csv file into MySQL table by using MySQ.

Importing CSV file using MySQL Workbench. MySQL workbench provides a tool to import data into a table. It allows you to edit data before making changes. The following are steps that you want to import data into a table: Open table to which the data is loaded.

To create a diagram from existing database you need to use reverse engineering functionality to create a model.

To reverse engineer database go to menu Database and choose Reverse Engineer... option.

Provide connection details to your database and click Next. Wait for the connection and click Next again.

When successfully connected wizard will show you list of available schemas on the server. Select the ones you want to reverse engineer.

Wait for the schemas being read and continue with Next. On next screen you have an option to select object types and filter specific objects. Let's ignore it and import all objects. Click Execute >.

Wait for reverse engineering to take place and when done continue with Next. Final screen shows you a summary of the import. Close with Finish.

Default diagram

When the process ends with success you get a new model (more about models here) with default diagram with all tables and views.

Clean out diagram

What you probably want to do right after you created a default diagram is to remove unnecessary tables and views and arrange tables to make it easier to grasp.

To remove table from diagram select it, right click and choose Remove Figure option.

Mysql Workbench Alter Table

Be careful not to choose Delete option as it will remove table not only form diagram but also your model catalog. Without a warning!

Arrange tables

To arrange tables you can try autoarrange option, but you'll need some manual work on top of that.

Mysql Workbench Edit Table Data Modeler

To use autoarrange go to menu, select Arrange and Autolayout.

To manually arrange tables simply select them and move around when you feel they fit best. Good luck.

Save model

Once you have completed your diagram make sure to save it. It is saved in a MySQL Workbench model in a .mwb file in Documents folder.

Export diagram

When your diagram is complete and safe it you can export it to png, pdf, ps or svg.

Mysql

To export diagram go to menu, select File, then Export, select one of the available formats and provide folder and filename.

Here is my diagram:

See it in other formats:

A better way to share diagrams: Dataedo

There is a better way to create and share diagrams for existing databases - Dataedo. Here is a sample export of complete database documentation with diagrams:

Mysql Workbench Edit Row

A few of the benefits:

Mysql Workbench Edit Table Data Query

  1. Easy and convenient sharing in interactive HTML
  2. Draw diagrams for databases with no FK constraints
  3. Attach complete data dicionary