Quantcast
Channel: CodingThis
Viewing all articles
Browse latest Browse all 3

MySQL Workbench on Windows: The Pros, The Cons, and The Quirks

$
0
0

I used phpMyAdmin for a dog’s age before using MySQL Workbench on a regular basis. While MySQL Workbench on Windows 7 is much heavier (and slower) than the super-slim Adminer, it provides a number of features that make creating and maintaining schemas in MySQL easier – including the ability to print out a visual depiction of your database.

System Catalogs Available (But Not By Default!)

Getting started with Workbench is easy. On the home page, click New Connection in the left-hand column to connect to a running MySQL instance. Once a connection is created, you can double-click it in the Open Connection to Start Querying window to open the SQL Editor, which provides visual access to all of the schemas and database tables defined in your MySQL instance.

You may find something strange when you first open this window, however: all of the meta-tables in the system catalog – such as information_schema and mysql – are missing. They’re not actually missing, but hidden by Workbench. To show them, click Edit->Preferences…, select the SQL Editor tab, and click the Show Metadata Schemata option. The next time you open a SQL Editor window, you’ll be able to see and query the metadata tables along with user-defined tables.

Altering Tables and Defining Foreign Keys

For those of us who don’t write Data Definition Language (DDL) every day, MySQL Workbench’s visual interface simplifies defining and altering tables. By right clicking on an existing table in the SQL Editor and selecting Alter Table, we can modify any of the table’s features, including column names and data types, triggers, indexes, and partitions.

In particular, MySQL workbench makes it easy to add foreign key relationships. Click on the Foreign Keys tab, enter a value for Foreign Key Name, and select the table to which the foreign key refers. MySQL Workbench will automatically populate the Column table. When you select the column in the current table that you want linked, MySQL Workbench will take its best (usually correct) guess as to the column you intend to reference in the target table.

Executing SQL Scripts (Well, Part of Them)

One thing that MySQL Workbench doesn’t do well (as of v5.2.29) is handle large SQL scripts. You can open a SQL script by pressing Ctrl+Shift+O. Unfortunately, Workbench seems to truncate large files after a certain number of bytes, as seen in this SQL export of Microsoft Access’ Northwind database.

This is one case where you’ll want to use the Run File command in Adminer – or simply crack open a Windows command prompt and execute the mysql command-line executable directly:

mysql –h hostname_or_ip –u username –-password="pass" –-silent < filename.sql

Visual Design of Databases with EER Diagrams

By far the coolest feature of MySQL Workbench is the support for Extended Entity Relationship (EER) diagrams. EERs support modeling of a database in the abstract – defining its entities (tables), data (columns), and relationships. A good EER tool – one that can both create a schema from an EER diagram, and reverse engineer a diagram from an existing schema – can run in the hundreds or thousands of dollars. Workbench provides the basics of EER diagramming for free.

To try out this feature quickly, you can reverse engineer one of your existing databases to produce a visual map of your data layout. On the Home page of MySQL Workbench, click Create EER Model From Existing Database. Walk through the steps to connect to your MySQL instance, select a database, and select which tables you wish to depict. MySQL Workbench will generate an EER diagram, with relationships drawn to represent foreign key references.

(In my installation of MySQL Workbench 5.2.29, the headers for the data entities render as black. To change this, click on the entity, and change the color property in the lower-left Properties Editor window to #FFFFFF.)

Once you’ve generated an EER diagram, you can modify it to your liking. You can click the File->Export command and then forward engineer your changes back into a SQL file as either a SQL CREATE script or a SQL ALTER script. If you’re importing databases to print out a visual depiction of your data layout, you can export the diagram to SVG, PNG, PDF, or PostScript.

Whether you use MySQL Workbench as your primary MySQL administration tool is up to you. Even if it’s not your first choice for administration, however, MySQL Workbench’s EER tools and visual interface for modifying tables quickly make it well worth installing.

The post MySQL Workbench on Windows: The Pros, The Cons, and The Quirks appeared first on CodingThis.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images