MATLAB串連MySQL資料庫

來源:互聯網
上載者:User

標籤:

  今天開始看《MATLAB資料分析與挖掘實戰》,學習了下用MATLAB串連MySQL資料庫,環境win7,32bit,MySQL5.7.12,MATLAB2013B  

  首先,從這裡下載驅動的壓縮檔(我選的第一個),解壓,將mysql-connector-java-5.1.39-bin.jar放到MATLAB安裝檔案下(理論上放在其他地方應該也可以,因為之後要指定驅動的路徑)。

   之後,直接執行以下代碼即可成功串連,並進行簡單的資料轉存。

%%MySQL資料庫匯入資料clear;% 初始化參數sqlquery = ‘SELECT u.user,u.host FROM user u‘;   % 查詢指令碼dbname = ‘mysql‘;                                               % 資料庫名稱username = ‘root‘;password = ‘你的資料庫密碼‘;host = ‘localhost‘;dpath = ‘D:\matlab\java\jar\mysql-connector-java-5.1.39-bin.jar‘; %MySQL驅動路徑datafile = ‘mysql_data.xls‘;                                  % 資料儲存路徑%%  串連資料庫並查詢javaaddpath(dpath);conn = database(dbname,username,password,‘Vendor‘,‘MySQL‘,‘Server‘,host);curs = exec(conn,sqlquery);                                  %執行查詢setdbprefs(‘DataReturnFormat‘,‘cellarray‘);           %設定資料格式curs = fetch(curs);%% 儲存資料data = curs.data;xlswrite(datafile,data);

  這裡,我嘗試將資料儲存在,尾碼.xlsx的檔案裡面,發現不可以,可能是還不支援這個較高的office版本。

MATLAB串連MySQL資料庫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.