MariaDB ODBC – How to Query Excel Using MariaDB ODBC Driver

excelmariadbodbc

I'm using MariaDB ODBC driver version 3.0.2 for Windows(on Windows 10) and can't get excel (Excel 2013) to query the database. I'm able to connect to my MariaDB server using HeidiSQL and query just fine, and my PHP application can query just fine. Now I would like to start pulling data for analytics.

I've setup the DSN using the "ODBC Data Source" tool under Administrative Tools in the control panel. I've just left all of the options blank. Below are some screenshots of how I setup the DSN.

Screen 1/5
Screen 2/5
Screen 3/5
Screen 4/5
Screen 5/5

When trying to setup the connection in Excel, I go to the data tab and from the "From Other Sources" drop down, I click Microsoft Query.

From MS Query

Then I select my data source (DSN) from the list and click "OK". Then I get two errors. The first error says "String data, right-truncated" and the second error says "Couldn't read this file". Screenshots below.

First Err
Second Err

I'm not sure what is causing this. I've tried using the servers IP address and the servers resolvable name, and I've tried specifying a database. I've also tried specifying a connection character set and selecting the option for using compression. I've also tried enabling dynamic cursors and the option to return matched rows instead of affected rows. Nothing has made any changes.

UPDATE: This is still an issue for me. 6/21/2018

Best Answer

I've figured out how to execute custom queries against MariaDB in Excel.

  1. Create your DSN using the "ODBC Data Sources (32-bit)" desktop app and leave all options as the default, except the connection page settings and "Return matched rows instead of affected".
    Matched rows
  2. In Excel, on the sheet you want the query to show up on, on the data tab, select "From Other Sources" -> "From Data Connection Wizard".
    Connection Wizard
  3. In the dialog that pops up, select "ODBC DSN" and click "Next".
  4. Find the DSN you created earlier and click "Next".
  5. Now you need to select a table, just one. (We will change this later)
  6. Click "Next", then "Finish", then "OK". The data from your table should populate the sheet, starting in what ever cell you specified before hitting that last "OK".

Okay, That's great! But how do I run a custom query with joins and a where clause? Read on my friend.

  1. Select any cell in the table that resulted from the above steps.
  2. In the design tab (should have opened when you clicked into the table) select the "Properties" button.
    enter image description here
  3. Click the "Connection Properties" button beside the "Name" field.
    enter image description here
  4. Now, on the "Definition" tab, in the "Command text:" field, you can paste in your query.
    enter image description here

I've tested this with basic joins and where statements. Everything seemed to work fine, so this should be enough to get you started. I have not tested sub-queries or any other advanced features yet.