ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Using the MySQL database in ROS Jade project

asked 2015-10-12 01:17:39 -0600

Sergey I. gravatar image

Hello! Who can give a reference to a working example of using the MySQL database in the ROS Jade project? The simplest example of cpp code mysql_init() and the contents of files cmakelists.txt and package.xml. I've seen similar questions, but there is not complete answer.

edit retag flag offensive close merge delete


Not an answer, but this shouldn't be any different from using MySQL without ROS: any example you can find elsewhere showing how to create a CMakeLists.txt for a MySQL program should work. ROS/Catkin does not add anything here. Just make sure to build_depend on libmysqlclient-dev.

gvdhoorn gravatar image gvdhoorn  ( 2015-10-12 03:53:44 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-05-30 20:46:14 -0600

I did this in Kinetic, but I think it's same in Jade.

  1. Install Ubuntu, ROS and MySQL Server (Please search instruction yourself)
  2. Install libmysqlclient-dev (sudo apt-get install libmysqlclient-dev)
  3. Create catkin package (follow tutorial)
  4. Make sure following code in "package.xml"



  <cpp lflags="-lmysqlclient"/>

5. Make sure following code in "CMakeList.txt" of your package, sequence is important.


find_package(MySqlClient REQUIRED)




6. Create a folder named "cmake-modules" in your package folder. This name is follow 1st line of code in step 5.

7. Copy contents in this URL: save it to "FindMySqlClient.cmake", in the folder you created in step 6.

8. In your .cpp file, add this include line:

    #include <mysql/mysql.h>

9. Here is a simple sample to get data from sys database.

    MYSQL *connection;  
    MYSQL_RES *result;  
    MYSQL_ROW row; 

    connection = mysql_init(NULL);
    connection = mysql_real_connect(connection, "mysqlserver", "username", "password", "sys", 0, NULL, 0);

    if(mysql_query(connection, "SELECT * FROM sys_config"))  
        ROS_INFO("Query Error: %s", mysql_error(connection));  

        result = mysql_use_result(connection); 
        for(int i=0; i < mysql_field_count(connection); ++i)  
            std::stringstream ss;  
            row = mysql_fetch_row(result);  
            if(row <= 0)  
            for(int j=0; j < mysql_num_fields(result); ++j)  
                ss << row[j] << " ";  
            ROS_INFO("%s", ss.str().c_str());  

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-10-12 01:17:39 -0600

Seen: 1,265 times

Last updated: May 30 '16