2012-11-14

If you plan to use the MySQL Workbench Migration Wizard to migrate databases from PostgreSQL to MySQL you first need to configure an ODBC driver to connect to your PostgreSQL server.
In this post I’ll cover how to set up and configure psqlODBC, the official ODBC driver for PostgreSQL.
Installing the psqlODBC Driver
The procedure is different for every platform so make sure to follow the instructions that correspond to the OS where you have MySQL Workbench installed. The driver needs to be installed in that machine, as explained in the MySQL Workbench documentation.
Windows
If you are running MySQL Workbench on Windows download the MSI package for psqlODBC. Go to its download page (http://www.postgresql.org/ftp/odbc/versions/msi/) and pick the most recent file from the list. (The most recent one is at the bottom of the page.)
Unzip the downloaded file and install the provided MSI package. This is all you have to do. You can skip the rest of this post.
Linux
The Migration Wizard uses iODBC as a driver manager for all of its ODBC connections in Linux. This may give you some troubles because most Linux distributions provide ODBC drivers compiled against unixODBC. This is another driver manager not supported by MySQL Workbench so you won’t be able to use those drivers unless you compile them against iODBC. Here’s what you should do.
Make sure that you have iODBC installed. If you are using Debian, Ubuntu or another Debian based distro, type this command in your terminal:
$> sudo apt-get install iodbc libiodbc2-dev libpq-dev
For RPM based distros (RedHat, Fedora, etc.) type this command instead of the previous one:
$> sudo yum install iodbc iodbc-dev
Now we need to install the PostgreSQL ODBC drivers.
Download the psqlODBC source tarball from here. Use the latest version available for download. As of this writing the latest version corresponds to the file psqlodbc-09.01.0200.tar.gz. Extract this tarball to a directory in your hard drive and open a terminal and cd into that directory.
Type this in the terminal window:
$> ./configure --with-iodbc --enable-pthreads
$> make
$> sudo make install
Verify that you have the file psqlodbcw.so in the /usr/local/lib directory.
Mac OS X
To build psqlODBC in Mac OS X, you need to have Xcode and the “Command Line Tools” additional component installed, so that the gcc compiler is available. You can get Xcode for free in the AppStore and install the Command Line Tools from Preferences -> Downloads.
Download the psqlODBC source tarball from here. Use the latest version available for download. As of this writing the latest version corresponds to the file psqlodbc-09.01.0200.tar.gz. Extract this tarball to a directory in your hard drive and open a terminal and cd into that directory.
Type this in the terminal window:
$> ./configure --with-iodbc --enable-pthreads
$> CFLAGS="-arch i386 -arch x86_64" make
$> sudo make install
Registering your ODBC Driver (Linux and Mac OSX)
Open the iODBC Data Source Administrator application either by typing iodbcadm-gtk in the command line or by launching it from the Overview page of the MySQL Workbench Migration Wizard, using the Open ODBC Administrator button. From the main MySQL Workbench screen you can start the Migration Wizard by clicking on the Database Migration launcher in the Workbench Central panel or through Database > Migrate in the main menu.
Go to the ODBC Drivers tab. You should have something like this:

Click on the Add a driver button and fill the values as shown here:

After you click OK you should have the psqlODBC driver registered.

Show more