Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Embedded MySQL server
QtWS25 Last Chance

Embedded MySQL server

Scheduled Pinned Locked Moved General and Desktop
qmysqlqsqldatabase
9 Posts 5 Posters 4.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SebastianS
    wrote on 13 Aug 2015, 04:45 last edited by
    #1

    Hey guy, does somebody have experience in setting up an embedded MySQL server with Qt and can show some code how its done?

    1 Reply Last reply
    0
    • N Offline
      N Offline
      NetZwerg
      wrote on 13 Aug 2015, 05:21 last edited by
      #2

      As far as I understood you just link to the libmysqld and start it by calling mysql_library_init() (end it before application exit with mysql_library_end()). For every thread that likes to access any mysql-function (so any QSql* function) call the corresponding thread init mysql_thread_init() (and mysql_thread_end()).

      The rest should behave as it has been with a default mysql server.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SebastianS
        wrote on 13 Aug 2015, 08:33 last edited by SebastianS
        #3

        I tried this code from the MySQL reference but it crashes when it comes to the point mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "libmysqld_client");. Does somebody has a working exmaple for a embedded server?

        #include <mysql.h>
        
        static char *server_options[] = {"mysql_test", "--defaults-file=my.ini", NULL};
        int num_elements = (sizeof(server_options) / sizeof(char *)) - 1;
        static char *server_groups[] = {"libmysqld_server", "libmysqld_client", NULL};
        
        int main(int argc, char *argv[])
        {
            QSqlDatabase mydb;
            MYSQL *mysql;
        
            mysql_library_init(num_elements, server_options, server_groups);
            mysql = mysql_init(NULL);
            mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "libmysqld_client");
            mysql_options(mysql, MYSQL_OPT_USE_EMBEDDED_CONNECTION, NULL);
        
            mysql_real_connect(mysql, NULL, NULL, NULL, "database1", 0, NULL, 0);
        
            mydb = QSqlDatabase::addDatabase("QMYSQL", "con1");
        
            mydb.setDatabaseName("database1");
        
            if(!mydb.open())
            {
                qDebug() << mydb.lastError();
            }
        
            mysql_library_end();
            return 0;
        }
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          SebastianS
          wrote on 20 Aug 2015, 05:58 last edited by
          #4

          Is really nobody out there who got this working?

          M 1 Reply Last reply 20 Aug 2015, 08:30
          0
          • S SebastianS
            20 Aug 2015, 05:58

            Is really nobody out there who got this working?

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 20 Aug 2015, 08:30 last edited by
            #5

            Hi

            Seems that not that many try the MYSQL embedded.
            Even on
            http://stackoverflow.com/questions/16990142/qt-c-embedded-mysql
            No ones answers.

            And you did link with the libmysqld ?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SebastianS
              wrote on 20 Aug 2015, 11:45 last edited by
              #6

              Hi,

              Yes I did. As I figured out using the embedded server doesn't make sense anyway in my application as it is multithreaded and the embedded server supports only one connection at a time. I don't mark it as solved since I am never the less interested how this works out.

              M 1 Reply Last reply 20 Aug 2015, 11:50
              0
              • S SebastianS
                20 Aug 2015, 11:45

                Hi,

                Yes I did. As I figured out using the embedded server doesn't make sense anyway in my application as it is multithreaded and the embedded server supports only one connection at a time. I don't mark it as solved since I am never the less interested how this works out.

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 20 Aug 2015, 11:50 last edited by
                #7

                @SebastianS
                Ok.
                Strange it would just crash then.
                mysql_init did return "im happy" etc?

                Well multi threaded could still work using a semaphore to control write access but
                if you need concurrent access its of no use.

                Sadly I think the question will just slowly drift to other pages and no one will ever see it again.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 20 Aug 2015, 19:47 last edited by
                  #8

                  Hi,

                  AFAIK, you don't have to fiddle with raw MySQL c++ calls. You should be able to use Qt the exact same way as you would with a classic client server setup

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    Andre_Xavier
                    wrote on 8 Jan 2017, 11:19 last edited by
                    #9

                    Note on https://dev.mysql.com/doc/refman/5.7/en/libmysqld.html says: “The libmysqld embedded server library is deprecated as of MySQL 5.7.17 and will be removed in MySQL 8.0.“

                    Andre Xavier

                    1 Reply Last reply
                    2

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved