After swatting up on connecting QlikView to a MySQL database, I used the knowledge gained to create a similar set-up, this time with Microsoft Excel. This is how to dynamically connect to and query a MySQL database table directly from Microsoft Excel on a local development machine. I did this using Microsoft Office Professional 2013.
- Download and install the MySQL ODBC (mysql-connector-odbc-5.3.4-winx64.msi), and create a DSN. I used this excellent tutorial http://www.plaintutorials.com/install-and-create-mysql-odbc-connector-on-windows-7/ to create a DSN called dsnlocalhost
- Open Excel, open and save a new workbook or open an existing workbook
- Click on the Data tab
- Data Connection Wizard option
- Select the From Data Connection Wizard option
- Select the ODBC DSN option
- Select dsnlocalhost from the ODBC data sources list
- Click Next
- Select the database from the dropdown list
- Select the Connect to a specific table checkbox and select the table – you can also connect to a view
- Click Next
- Provide a user-friendly name (and other details) for the connection file
- Click Finish
- Your connection file will be saved – the default location is: C:\Users\<user>\Documents\My Data Sources
- You will now be prompted to Import Data, click OK
- Your spreadsheet will be populated with data
- Microsoft Query option
- Select the From Other Sources » From Microsoft Query option
- Your DSN will appear in the Choose Data Source pop-up; select the DSN you created above
- Ensure the Use the Query Wizard to create/edit queries checkbox is selected
- Follow the steps in the Query Wizard, optional steps are to add filters on rows
- Ultimately this creates a Query – you will be prompted to save the query – you can view at this stage
- Default location of connection: C:\Users\<user>\Documents\My Data Sources
- To view the Query, and potentially change it,
- On the Data tab, select Connections
- Click the Properties button
- Select the Definition tab
- The query appears in the Command text window at the bottom
- Edit the Query manually
- Or edit the query using the Edit Query button which launches the MS Query Wizard which is a user-friendly interface that looks like MS Access.
Once you have created the connection, it can be reused in other workbooks – select Existing Connections from the Data Tab and your connection will be listed
If you used Option A, you could still use the Microsoft Query Wizard to make modifications:
- Data tab Connections
- Select your connection file
- Click Properties
- Click definition
- At the bottom of the window, you will see your SELECT query; you can manually edit it, or you can click Edit Query and use the Query Wizard