Why do I receive an error message in the output of the DATABASE function when I try to connect to a mySQL database using ODBC with the Database Toolbox?

2 views (last 30 days)
Why do I receive an error message in the output of the DATABASE function when I try to connect to a mySQL database using ODBC with the Database Toolbox?
I am using the Database toolbox to connect to a mySQL database on a Microsoft Windows computer. I am using the ODBC driver to connect to the database. I use the following code at the MATLAB command prompt:
conn = database('unixIndexDB','','');
conn.message
However, I get the following error message in the "message" field of the output structure "conn":
ans =
[MySQL][ODBC 3.51 Driver]You have an error in your SQL syntax. Check the manual that
corresponds to your MySQL server version for the right syntax to use near
'Connecting to mySQL' at line 1

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This error is thrown if the ODBC setup for the mySQL database is not correct for the data source. The configuration dialog box for mySQL data source settings in ODBC has a field for "SQL command on connect". This field should be set to an SQL command that is executed when someone tries to connect to the data source. This command has the following format:
use database_name
where database_name has to be the name of your data source that is provided in the configuration dialog box. If the USE command does not use the correct data source name, mySQL throws the error message above that is reflected in the "message" field of the output of the DATABASE command in MATLAB.

More Answers (0)

Products


Release

R13SP1

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!