Easy Database Schema Diagrams with DBVisualizerBy Matthew Magain
I’ve never particularly liked databases.
Don’t get me wrong–I love using them. You know, filling them with data, watching my users fill them with data, deleting my users’ data* … but as long as it’s all from the safety of a server-side programming language–I’ve never been a big fan of interacting with them directly. All that SQL just gives me a headache.
Sure, we’ve come a long way from the SQL command line. We have web-based tools, like phpmyadmin and phpPgAdmin. And if you don’t fancy doing your heavy lifting over http, there are desktop tools like MySQL Query Browser and TOAD. And frameworks like Rails have migrations now, so we’ve got all the tools we need, right?
Well, if your brain works anything like mine does, then you’ll agree that sometimes it’s nice to have a “big picture” view of things–a diagram of your data goes a long way to helping understand how it fits together. If your application only consists of three or four tables, then you may already have one of these sketched out on a bit of paper. But none of the tools I mentioned above can provide us a picture of what our database actually looks like–which tables have foreign key constraints that point where. Once your database schema grows beyond a handful of tables, this can become a significant issue. And if you’ve ever had to get your head around someone else’s schema in a short period of time, you’ll know what I’m talking about–sure, you could try and visualize this in your head, or sketch it out with pen and paper after poking around using a bunch of queries. But now there’s no need to.
DBVisualizer is a slick database client that creates a schema diagram of your database. It’s written in Java, so runs on just about any platform, and it’s dead easy to set up and use. In this post I’ll show you how to install DBVisualizer and use it to produce beautiful schema diagrams of your MySQL database.
To demonstrate how to create your schema diagram, I’ll make a few assumptions:
- You’re able to connect to a MySQL database–either locally or on your production server.
- You have a Java Runtime Virtual Machine installed on your local machine. No problem if you haven’t–you can either download and install one manually or choose a version of the DBVisualizer installer that includes it.
- You already have a schema in your database of which you wish to create a diagram.
- You’re using the InnoDB engine for your tables. You can still create a schema diagram if you’re using MyISAM, but it won’t reflect any foreign key constraints, as these are ignored by MyISAM. If you don’t know, you’re probably using MyISAM.
Follow these instructions:
There are a few versions of DBVisualizer. DBVisualizer Free performs all of the visualization coolness, but contains limited features (such as only being able to perform one SQL query at a time–possibly enough to make you want to upgrade to a personal license if you get addicted to the other stuff). The version at the time of writing is 5.1.1.
Installing DBVisualizer is as simple as it gets. Whether you’re running Windows, Mac, Linux or a general Unix platform, you have the choice of a wizard-style installer or just unpacking a compressed archive to the folder of your choice. That’s it!
DBVisualizer doesn’t come with a MySQL driver out of the box, but adding one is easy. Download the MySQL JDBC driver, and unzip the archive to a folder of your choice (there’ll be a
jarfile in there somewhere, which is what we’re after).
Then launch DBVisualizer and select Driver Manager from the Tools menu.
On the left, select MySQL, and in the User Specified tab of the Driver File Paths form, click the Browse icon and choose the
jarfile that we extracted earlier.
To connect to your database, choose Database > Create Database Connection. You can either follow the built-in connection wizard to establish your connection, or enter it manually. There’s not really much to it; all you need is:
- the server name (usually just
localhost) and port number that your database runs on (usually 3306 for MySQL)
- your database username and password
To enter this information manually, set Database Type to MySQL, select MySQL from the Driver (JDBC) dropdown, and enter your Database URL and username/password. The URL will take the format:
I thought I’d take a poke around the schema used by the Habari open source project. After installing it locally, I therefore used the following. The schema can be omitted if you don’t want to specify one by default.
Click Connect, and your connection should be established!
- the server name (usually just
Now that you’re connected, double-click on the schema you wish to explore, select Tables and then click on the References tab to view your schema diagram (complete with pretty animations). You have some control over what gets included in the diagram, including being able to view the schema using a variety of layouts, zoom in and out, and include or exclude things like column details and foreign key names.
That’s all there is to it! Whether you’re trying to flesh out a schema for an application of your own design, or trying to understand an existing application in order to write a plugin or fix a bug, an application like DBVisualizer can certainly make your database design, development and maintenance a heck of a lot easier.
*I was of course, just joking about deleting my users’ data. Well, mostly.