Bienvenido! - Willkommen! - Welcome!

Bitácora Técnica de Tux&Cía., Santa Cruz de la Sierra, BO
Bitácora Central: Tux&Cía.
Bitácora de Información Avanzada: Tux&Cía.-Información
May the source be with you!

Friday, December 9, 2011

MySQL diagrams on OSX

Quick and Dirty MySQL Diagrams with EOModeler
posted 1645 days ago

Whenever I take on a new project with an existing database the first thing I like to do is generate an entity diagram of all the tables. On OSX you can buy or download any number of third party packages to model tables, but here’s how to do it with software you already own: WebObjects and EOModeler.
The executive version:
Create a MySQL database with Foreign Key relationships; then install the proper JDBC driver for MySQL; finally point EOModeler to your database to generate the diagram.
Although these steps are covered in various places on the web, here’s the whole thing step by step in detail. I assume you have MySQL 5 and OSX 10.4.9.
  • First, make sure you’re working with InnoDB tables. By default MySQL MyISAM tables will recognize but not enforce Foreign Key relationships. When creating MySQL tables remember to add ENGINE=InnoDB to your CREATE statements.
  • Next, you’ll need to install the correct driver so Java can connect to MySQL. Download Connector/J to your desktop. As of this writing the most current stable release is 5.0.
  • Untar the download and look for the following file: mysql-connector-java-5.0.6-bin.jar. You need to copy the jar file to your Java Extensions folder. To do so, open terminal and type the following commands:
cd ~/Desktop/mysql-connector-java-5.0.6 sudo cp mysql-connector-java-5.0.6-bin.jar /Library/Java/Extension [Enter your password when prompted]
  • Next, you’ll need to install EOModeler if haven’t already. It’s included with WebObjects. Search with Spotlight for EOModeler. If nothing turns up, or if you hate Spotlight, open finder and look for the following folder: /Developer/Applications/WebObjects.
    • If you don’t have EOModeler, you need to install WebObjects. Find your OSX install DVD (darn!) and pop it in your Mac. Browse the contents and look for the WebObjects package, then double click to install. That’s all.
    • If you do have EOModeler you can skip to the next step.
  • Launch EOModeler and select Model > New to launch the New Model Wizard. In the list of available adapters select JDBC and click Next.
  • Provide the connection information for your MySQL database. The username and password are simply the username and password you use for your particular MySQL database. Enter the following value for your URL:
jdbc:mysql://localhost/yourdatabasenamehere
  • The Wizard will next ask you what to include in your model. You might want to uncheck “Ask about relationships” if you have a lot of tables. Click Next.
  • Select the tables you want to diagram. For starters, just click Select All and then click Next, then click Finish.
  • EOModeler then generates a list of objects, which isn’t so useful. From the Menu, select Tools > Diagram View.
Schweet! You can save the generated diagram and reopen it in Xcode. You should end up with a diagram that looks something like the image below, foreign keys and all. Tip: if you end up with am archipelago of unconnected tables, you’re probably working with MyISAM tables instead of InnoDB.
Questions? Post them in the comments here. Just don’t expect any replies Sunday night. I’ll be respecting the Bing.


No comments: