MATLAB: Is it possible to use SSL with MySQL with the Database Toolbox 3.5 (R2008b)

Database Toolbox

I would like to connect to a MySQL database using SSL to encrypt the connection. I am using JDBC and the 'com.mysql.jdbc.Driver' driver.

Best Answer

In order to make use of SSL encryption to connect to your database, you will need the following:
1. The assistance of your database administrator to configure the MySQL server to accept SSL connections.
2. The SSL PEM public-key file that corresponds to your server's encryption key.
Here is the procedure:
1. Follow the steps in the MySQL documentation below to to verify that...
(a) Your MySQL server has SSL support,
(b) You can use the MySQL Command-Line Client to connect to the server using SSL:
In particular, the following SQL command may be informative:
show variables like 'have_ssl'
If the answer from your server is 'NO', then the server has no SSL support compiled into it. If the answer is 'DISABLED', your system administrator does not start the MySQL server with SSL enabled. If the answer is 'YES', you may be able to use SSL.
2. Follow the steps in the MySQL documentation below to configure your Java environment to use the server's PEM certificate with JDBC. You can specify Java options for MATLAB by modifying or creating the 'java.opts' file located here:
$MATLABROOT\bin\ARCH\java.opts
Here, $MATLABROOT is the directory where MATLAB is installed, and $ARCH is your computer's architecture, for example 'win32'.
3. Restart MATLAB
4. Modify your call to the DATABASE command from
hconn = database('DatabaseName','UserName','Passwd',...
'com.mysql.jdbc.Driver',...
'jdbc:mysql://HOST:PORT/DatabaseName')
to
hconn = database(''DatabaseName','Username','Passwd',...
'com.mysql.jdbc.Driver',...
'jdbc:mysql://HOST:PORT/DatabaseName?verifyServerCertificate=false&useSSL=true&requireSSL=true&')
Please note that the trailing '&' in the URL is required.