Connect MySQL to MATLAB?

前端 未结 2 1412
一向
一向 2020-12-31 16:04

I would like to know how to connect a MySQL database to MATLAB software. I downloaded the jdbc connector but I\'m not getting how to specify the path.

相关标签:
2条回答
  • 2020-12-31 16:29

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

    Let me quote:

    1. open the classpath.txt file in [matlab path]/toolbox/local/ and add the following line to it (you can download jar file from http://dev.mysql.com/downloads/connector/j/, and after extract you can move it to under the folder : /usr/share/java)

      [path to unzipped jdbc driver package]/mysql-connector-java-3.1.12-bin.jar
      
    2. create a database in mysql (can look up here how to do that)

    3. 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’)
      
    0 讨论(0)
  • 2020-12-31 16:45

    I suppose here that you have created a database called 'mybase' and you use 'root' user without password (don't do that in real life).

    You have to remember to add the mysql connector jar file path to java classpath. You can do this by either adding the path to classpath.txt (\toolbox\local) or by using javaclasspath command directly from Matlab.

    You can establish your connection like this:

    dbname = 'mybase';
    username = 'root';
    password = '';
    driver = 'com.mysql.jdbc.Driver';
    dburl = ['jdbc:mysql://localhost:3306/' dbname];
    
    javaclasspath('path-to-mysql-connector\mysql-connector-java-VERSION-bin.jar');
    
    conn = database(dbname, username, password, driver, dburl);
    
    0 讨论(0)
提交回复
热议问题