MATLAB connection MySQL Database

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.