Set up a JDBC connection from Matlab to MySQL on osX

2 次查看(过去 30 天)
I have set up MATLAB (2016b 64-bit) to interact with the local MySQL server. I followed the instructions and created a javaclasspath.txt file on Matlab's prefdir location where I saved the mysql-connector-java-5.1.40-bin.jar location. Afterwards, I used the native Matlab Database Explorer App to set up a connection, where after following the steps Matlab created a .mat file on the current folder (see picture):
As you can see above the .mat file contains a cell array with the listed inputs. My question is the following, now that I have successfully set up the server I want to create a "conn = database()" variable. How can I do that? I have read the Matlab guide and this guide on Stackoverflow but I get an error "Invalid connection" when I execute :
conn = database('Data_Science', 'root', '*****', 'com.mysql.jdbc.Driver', 'jdbc:mysql://localhost:3306/Data_Science?useSSL=false');
e = exec(conn,['create table BULKTEST (salary decimal, '...
'player varchar(25), signed_date varchar(25), '...
'team varchar(25))']);
Is something wrong with my code above? Did I write the information wrong? The second part (e) is c/p from Matlab's site. So my doubts are about conn.
SOLUTION:
Ok, the problem was on the conn command. When I used this code, without including the ?useSSL=false :
conn = database('Data_Science', 'root', '*****', 'com.mysql.jdbc.Driver', 'jdbc:mysql://localhost:3306/Data_Science');
I received this warning:
Fri Feb 10 13:48:03 GMT 2017 WARN: Establishing SSL connection without
server's identity verification is not recommended. According to MySQL
5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established
by default if explicit option isn't set. For compliance with existing
applications not using SSL the verifyServerCertificate property is set to
'false'. You need either to explicitly disable SSL by setting useSSL=false,
or set useSSL=true and provide truststore for server certificate verification.
So I looked online and the solution was to include ?useSSL=false at the end of conn. Indeed, this worked as I no longer received any further warnings, but when I checked the conn on workspace there was a line with the following message:
The connection property 'useSSL' only accepts values of the form: 'true',
'false', 'yes' or 'no'. The value 'falseData_Science' is not in this set.
Which I never noticed before, that caused the connection error. So I just reversed back to the original conn, amending the ?useSSL=false change I made. Now, I still receive the warning but it works.
  4 个评论
Kojiro Saito
Kojiro Saito 2017-2-11
It's good you could work around by yourself. The last error "The value 'falseData_Science' " seems strange.
Anyway, without useSSL option, you can also run exec command by defining "conn" as
conn = database('Data_Science','root','PASSWORD','Vendor','MySQL', 'Server', 'localhost', 'PortNumber', 3306);
Two key-value pairs, 'Server', 'localhost' and PortNumber', 3306 can be omitted because they're default values.
Ivan Surovtcev
Ivan Surovtcev 2017-8-17
Have the same problem. Same error and the 'falseData_Science' in my case is 'falseDataBaseName'.
Does it look like Matlab incorrectly merges strings when trying to make a connection?

请先登录,再进行评论。

回答(1 个)

Hannes Greim
Hannes Greim 2018-8-22
Try adding an "&" at the end of the new portion of the string:
?useSSL=false&
  3 个评论
Shay Rotics
Shay Rotics 2019-1-31
Thanks, had the same problem of the matlab concatanating the 'false' to 'falseuser_db' and the '&' solved it. Many thanks
Arpan Badeka
Arpan Badeka 2019-4-4
This has been fixed in later releases. To make it work keep the first argument as empty.
conn = database('', 'root', '*****', 'com.mysql.jdbc.Driver', 'jdbc:mysql://localhost:3306/Data_Science?useSSL=false');

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Database Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by