Today began to read the "MATLAB data analysis and mining actual combat", learning to use MATLAB to connect MySQL database, environment win7,32bit,mysql5.7.12,matlab2013b
First of all, download the driver's compressed file from here (I choose the first), unzip, put Mysql-connector-java-5.1.39-bin.jar into the MATLAB installation file (ideally in other places should also be possible, because later to specify the path of the drive).
After that, you can successfully connect and perform a simple data dump by executing the following code directly.
%%mysql Database Import data clear;% initialization parameters SQLQuery = ' SELECT u.user,u.host from user U '; % Query Script dbname = ' mysql '; % Database name username = ' root ';p assword = ' Your database password '; host = ' localhost ';dp ath = ' D:\matlab\java\jar\ Mysql-connector-java-5.1.39-bin.jar '; %mysql Drive Path datafile = ' Mysql_data.xls '; % data save path percent connection database and query Javaaddpath (DPATH); conn = Database (Dbname,username,password, ' Vendor ', ' MySQL ', ' Server ', host ); curs = exec (conn,sqlquery); % execution Query Setdbprefs (' Datareturnformat ', ' Cellarray '); % Set data Format Curs = Fetch (curs), percent save data = Curs.data;xlswrite (Datafile,data);
Here, I try to keep the data in the suffix. xlsx file inside, and it is not possible to find that the higher Office version is not supported.
MATLAB connection MySQL Database