Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Adding MySQL driver to Qt
Forum Update on Monday, May 27th 2025

Adding MySQL driver to Qt

Scheduled Pinned Locked Moved Unsolved C++ Gurus
2 Posts 2 Posters 2.6k 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.
  • U Offline
    U Offline
    uuecm
    wrote on 28 Oct 2019, 12:25 last edited by
    #1

    Hello,

    I am trying to connect to a MySQL Database using Qt (5.12.5) on macOS 10.15.
    I have the MySQL community Server installed (https://dev.mysql.com/downloads/mysql/).
    Therefore the libmysqlclient.dylib is available in /usr/local/mysql-8.0.18-macos10.14-x86_64/lib/libmysqlclient.dylib

    However I get the following error, when trying to compile my project:

    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
    

    I tried to head to /Users/USERNAME/Qt/5.12.5/Src/qtbase/src/plugins/sqldrivers/mysql and run qmake. This resulted in the following error

    Cannot read /qtsqldrivers-config.pri: No such file or directory
    /Users/USERNAME/Qt/5.12.5/clang_64/mkspecs/features/qt_plugin.prf:59: Cannot write file /mkspecs/modules-inst/qt_plugin_qsqlmysql.pri: Cannot create parent directory
    

    I am an absolute noob to qt and have no idea what to do from here.
    Could you explain me what I have to do in order to get the MySQL driver running?

    Thank you so much!

    1 Reply Last reply
    0
    • B Offline
      B Offline
      brochiha
      wrote on 28 Oct 2019, 15:22 last edited by
      #2

      These are the instruction that I made after installed it on my Ubuntu 18.04 linux install. Maybe it will help you
      Download QT 5.12.4 from QT website using the downloads buttons and then select open source and download

      After Download is complete go to Downloads folder and run the installer
      (for new ubuntu users – right click on file in downloads and select permissions and select option at bottom)

      Download latest QT that is known to have LTS (long term support)
      -Run installer
      -deselect android stuff and make sure that you select the dev tools and sources at the bottom
      install QT

      download and install mysql and dev packages

      sudo apt-get install libglu1-mesa-dev
      sudo apt-get install build-essential
      sudo apt-get install libmysqlclient-dev
      sudo apt-get install libssl-dev

      navigate to your Qt folder/5.12.4/Src
      -run config file
      -./configure -plugin-sql-mysql

      Navigate to qt source ie...Qt/5.12.4/Src/qtbase/src/plugins/sqldrivers/mysql
      -run the QT qmake
      /home/bj/Qt/5.12.4/gcc_64/bin/qmake MYSQL_PREFIX=/usr/include/mysql/ mysql.pro

      locations may vary depending on where you installed Qt during the installation process and what version of Ubuntu you may be using

      after running qmake
      -run make
      -make install

      you should be set from here...if you have any more issues then refer to these articles to seek clarification

      https://forum.qt.io/topic/59449/qsqldatabase-qmysql-driver-not-loaded-build-mysql-plugin

      https://stackoverflow.com/questions/37369480/qsqldatabase-qmysql-driver-not-loaded-on-ubuntu-15-04-64bits

      https://doc.qt.io/qt-5/sql-driver.html#qmysql-for-mysql-4-and-higher

      https://forum.qt.io/topic/36072/qmysql-driver-not-loaded-on-ubuntu/15

      1 Reply Last reply
      0

      1/2

      28 Oct 2019, 12:25

      • Login

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