Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Adding MySQL driver to Qt
uuecm last edited by
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!
brochiha last edited by
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)
-deselect android stuff and make sure that you select the dev tools and sources at the bottom
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
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
you should be set from here...if you have any more issues then refer to these articles to seek clarification