MacLochlainns Weblog

Michael McLaughlin's Technical Blog

Site Admin

MySQL on Windows 7

with 7 comments

This shows you how to setup MySQL Connector/ODBC driver, add a new data source in Windows 7, and a new data import source in Excel 2007. As with other “how-to” posts, it includes screen shots to clear up any ambiguity.

Back in November 2008, I posted how you could query Oracle from Excel 2007. A few folks have asked for more instructions around the data source, and how to connect to a MySQL database. Unfortunately, it took me quite some time to get back to it. It was interesting to note when I attended the ACM Computation Biology Conference last August that so many folks are using MySQL as department data repositories. It was no surprise to find a need to connect Microsoft Excel to MySQL. After all, it is the de facto tool of many data analysts.

Install the MySQL Connector/ODBC Driver

  1. Downloading the MySQL Connector/ODBC is the first step. You need to choose the 32-bit or 64-bit version based on which version of the operating system and MySQL database installed. These instructions use the 64-bit version.

  1. The first message with be a security warning when you attempt to launch the MSI file. Click the Run button to start the installation.

  1. This is the first dialog of the MySQL Connector/ODBC driver. Click the Next button to continue.

  1. You can probably choose Typical, Complete, or Custom but I chose Custom. After picking a setup type, click the Next button to continue.

  1. You can see what you’re installing in this dialog. Click the Next button to continue.

  1. This dialog shows you were the libraries will be installed. Click the Next button to continue.

  1. This dialog is a progress bar, it should run to completion in a half minute or less. Wait until you’re prompted to take action.

  1. This is the last setup wizard dialog, you should click the Finish button to apply the change.

Install the MySQL Connector/ODBC Driver

  1. You need to create a data source in the operating system. You should open the Control Panel and click on the Administrative Tools menu item to begin the installation of a new data source.

  1. Click the Data Sources (ODBC) menu item to start the process.

  1. This is where you add a new User Data Source. Click the Add button on the right of the dialog box.

  1. The Create New Data Source dialog box should show the MySQL ODBC 5.1 Driver that you installed earlier. Click on it in the selection box, and then click the Finish button.

  1. The MySQL Connector/ODBC Data Source Configuration dialog prompts you for a Data Source Name (DSN), a description, a TCP/IP Server, a port number, a user, a password, and a database. I’ve entered a student user with a trivial student password, and a studentdb database. Before finishing with this dialog, you should click the Test to ensure you can connect to the database.

  1. The test should be successful and display the following message. Click the OK button to dismiss the affirmation of the test.

  1. After the test, you return to the first screen where you should see that you’ve added a MySQLExcel Data Source Name. Click the OK button to dismiss the affirmation of the test.

Setup Data Import

  1. After launching Microsoft Excel, click on the Data Ribbon. Click the From Other Sources button. In the drop down menu, click on the From Data Connection Wizard item, which launches the Data Connection Wizard.

  1. Choose the Other/Advanced item from the list of data sources. Click the Next button to continue.

  1. Choose the Microsoft OLE DB Provider for ODBC Drivers item from the list of OLE DB Provider(s). Click the Next button to continue.

  1. Choose the Connection tab in the Data Link Properties dialog. Under item #1, choose the Data Source Name (DSN) from the drop down box (set in a previous statement). Under item #2, enter the student user name and student password. Under item #3, enter the MySQL studentdb database. Click the OK button to continue.

  1. Click the Test Connection in the prior dialog to verify that you can connect. You should see the following message if the connection works. You can click the OK button to dismiss the Data Link Connection dialog. Then, click the OK button on the Data Link Properties dialog.

  1. This dialog lets you select a database and table. Select the studentdb database from the drop down menu. Then, pick the contact table.

  1. The last dialog lets you save the connection. Click the Finish button to save the connection.

  1. The Data Import Wizard is complete with the last step. Now, you must import the data into the existing worksheet or a new worksheet.

You should now have the rows from the table inserted into the spreadsheet, like this:

As always, I hope this helps those trying to sort through how this works. Naturally, a Visual Basic for Applications (VBA) solution is a better alternative once you’ve set up the data source.

Written by maclochlainn

February 15th, 2011 at 11:59 am

Posted in Uncategorized

7 Responses to 'MySQL on Windows 7'

Subscribe to comments with RSS or TrackBack to 'MySQL on Windows 7'.

  1. [...] moved the post to a page of it’s own [...]

  2. [...] Oracle ODBC Data Source [...]

  3. I tried this and it didn’t work — what I got is “Test connection failed because of an error in initializing provider. [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and the Application”. I am using Excel 2007 and under “Data Source name”, my DSN that I defined in the Control Panel –> ODBC Data Sources didn’t show up — I had to type it in.

    T Bee

    24 Oct 12 at 1:11 pm

  4. Can you answer these questions:

    Is the operating system 32-bit or 64-bit?
    Is the MySQL Server 32-bit or 64-bit?
    Is the MySQL Connector 32-bit or 64-bit?

    maclochlainn

    24 Oct 12 at 7:48 pm

  5. Working perfectly for me.. thanx

    Rajneesh

    6 Nov 13 at 1:39 am

  6. I came here after struggling to get a connection from 32-bit Excel (Excel 2007) to MySql using Windows 7 (64-bit). It seems that for this you need both the 32-bit and 64-bit ODBC drivers. And version 5.1.8 is the only (or most recent) version where the installer contains both.

    So, thanks for pointing me the right way!

    Ross Kavanagh

    28 Nov 13 at 2:04 pm

Leave a Reply