Feed on
Posts
Comments

i’ve been working on a gene identification / network modeling experiment for a couple of weeks now. i have tons of processed microarray data that now needs to be examined as well as further annotated by hand. since all the data has already been processed, a spreadsheeting package is unncessary; what i really need is a database to store all this information that doesn’t fit neatly into fixed rows and columns.

unfortunately, the easiest piece (read, nicest GUI) of database software around, Microsoft Access, doesn’t live on OS X. filemaker pro is also out, since i’d like to write perl scripts to interface with the database. next up was MySQL. this looked like a good option, especially since all the processed data currently lives in matlab; matlab advertises a database toolbox that eases transfer of data from matlab to MySQL.

here’s how i figured out how to get this working (on mac OS X):

1) download and install mysql.

2) download the jdbc driver here.

3) open the classpath.txt file in [matlab path]/toolbox/local/ and add the following line to it:

[path to unzipped jdbc driver package]/mysql-connector-java-3.1.12-bin.jar

4) create a database in mysql (can look up here how to do that)

5) to connect to the database you’ve created (call it “foo”), type into matlab:

>> conn = database(‘foo’,’[your user name]‘,”,’com.mysql.jdbc.Driver’,'jdbc:mysql://localhost:3306/foo’)

you can go ahead and try to use matlab’s confds command; i spent over an hour trying to get it to work with no luck. i have no idea why the command-line option works but the GUI one doesn’t.

6) start reading the sql and mathworks documentation, like i’m doing now, and learn how to be useful.

a note: this piece of documentation proved somewhat useful throughout this process; it’s actually more informative than the most current page on the mathworks support site.


Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

20 Responses to “how to get matlab to talk to mysql”

  1. on 10 Mar 2006 at 3:41 pm Christian Lepple

    Thank you very much for your detailed description how to connect Matlab to mysql with MAC OS 10.4. I have spent many useless hours to get it done. The problem was, there is a debuged JDBC driver (mysql-connector-java-3.1.12-bin-g.jar) that does not work. Maybe worth to know.

    Best
    Christian

  2. on 17 Mar 2006 at 4:26 am Anonymous

    mabe you can try this http://itswww.epfl.ch/~maret/software.php

  3. on 22 Sep 2007 at 2:59 pm Stephen Killingsworth

    I agree, this description is incredibly helpful!

    Thanks,
    -Stephen

  4. on 23 Jan 2008 at 7:58 am Ian

    Anyone got a compiled version of the above working?
    Seems like it is troublesome to set the classpath…

    In particular, the error:
    Undefined variable: “com.mathworks.toolbox.database.databaseConnect”

    Ian.

  5. on 30 Aug 2008 at 11:35 pm mahmud

    i faced an eror

    Undefined variable: “com.mathworks.toolbox.database.databaseConnect”

  6. on 15 Dec 2008 at 1:44 pm Yue

    Hi ,

    I went around here when searching how to work in matlab linked with mysql. Thanks alot for your help ( and I believe lots of people have been grateful to your amazing summarized information ragarding this)!

    I just wonder if I can create new tables via matlab to the database, or in other words, can we work in matlab just like we do in mysql itself? (and the only difference is just different language ?)

    cheers,
    Yue

  7. on 02 Apr 2009 at 3:14 am Fabre

    Your my man THANKS++++++…

  8. on 27 Apr 2009 at 5:19 am honza.mich

    Thank a lot for the clear and useful example.

    Honza M.

  9. on 22 Jul 2009 at 3:23 pm David

    Hello,

    I have done (to the best of my ability) exactly what was outlined above. However conn.Message continues to say:

    “JDBC Driver Error: com.mysql.jdbc.Driver. Driver Not Found/Loaded.”

    Does anyone have any ideas? Thanks in advance for your time.

    -David

  10. on 17 Sep 2009 at 10:48 am JK

    I’ve been trying for >1 hour. With your description it took me 5 min.

    Thank a lot.

    JK

  11. on 29 Sep 2009 at 10:03 am yasaswy

    hey i am getting a getting an error.

    Communications link failure

    Last packet sent to the server was 0 ms ago.

    plz help

  12. [...] Connection between Matlab and MySQL Posted 15 November 2009 Filed under: Uncategorized | Tags: code, matlab, mysql | here’s: http://desk.stinkpot.org:8080/tricks/index.php/2006/02/how-to-get-matlab-to-talk-to-mysql/ [...]

  13. on 12 Jul 2010 at 11:24 am Aaron

    Thanks, I have exactly the same situation; no luck with GUI but your post encouraged me to try connecting in the command window which worked perfectly. Any idea yet why the GUI is broken?

  14. on 20 Jul 2010 at 1:43 am Jonathan Karr

    Here’s a solution that doesn’t require the database toolbox: http://www.mathworks.com/matlabcentral/fileexchange/28237.

  15. on 11 Nov 2011 at 4:04 am Ramon Fincken

    I found this website: http://www.cims.nyu.edu/~almgren/mysql/ which also does not need the database toolbox.

    I have written a step by step installation instructions for Linux 64bit:
    http://www.ramonfincken.com/permalink/topic238.html

  16. on 24 Jul 2012 at 2:39 am Sriram

    Hey ,,

    Thanks for the post…
    Quite helpful..
    I am trying to write an entire variable into the databse with 1440 values in each variable.. Could you suggest the way forward in doing this ?

    sRiram

  17. [...] http://desk.stinkpot.org:8080/tricks/index.php/2006/02/how-to-get-matlab-to-talk-to-mysql/ [...]

  18. on 29 May 2013 at 5:20 am anjali

    I am working on ubuntu OS. I am confronting an error
    “Undefined function or variable ‘openmysqlconnection’”. openmysql connection is the function which includes all the data to connect to mysql db.

  19. on 10 Feb 2016 at 5:53 am adiarray

    try this

    url = ‘jdbc:mysql://localhost:3306/’;
    conn = database(‘matlab_db’, ‘root’, ”, ‘com.mysql.jdbc.Driver’, url);
    curs = exec(conn,’SELECT * FROM barang’);
    curs = fetch(curs)
    curs.data

    tableName = ‘barang’;
    fields = {‘kode_barang’, ‘nama_barang’, ‘deskripsi’, ‘harga’,'kategori’, ‘gambar’, ‘status’};

    %allData = {‘BRG004′, ‘KOMPUTER 4′, ‘Harga murah…..harga ok’, ’1250000′, ‘Komputer’, ‘kom4.jpg’, ‘Tersedia’};

    var1=get(handles.guivar1,’String’);
    var2=get(handles.guivar2,’String’);
    var3=get(handles.guivar3,’String’);
    var4=get(handles.guivar4,’String’);
    var5=get(handles.guivar5,’String’);
    var6=get(handles.guivar6,’String’);
    var7=get(handles.guivar7,’String’);

    allData = {var1, var2, var3,var4,var5,var6, var7};
    tic
    fastinsert(conn,tableName,fields,allData)
    toc

    % clear the table
    % deleteQuery = ['delete from ',tableName,';'];
    % exec(db,deleteQuery);

    or more detail:
    http://matlab-adiarray.blogspot.co.id/2016/02/matlab-lihat-dan-simpan-data-di-mysql.html

  20. on 23 Sep 2016 at 4:27 am Lyazzat

    Man, I have spent two days on trying to connect matlab to oracle database server. Mathworks guides are not helpful at all. Your post helped me in 5 minutes! Thank you so much!!!

Did I get this wrong? Let me know!

Trackback URI | Comments RSS

More blogs about http://desk.stinkpot.org:8080/tricks.