Qt World Summit: Register Today!

QSqlDatabase: QMYSQL driver not loaded

  • I realize that this topic has been covered but I'm not sure exactly how I need to solve it on my system.
    I try to use SQL in Qt and get the following error:

    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7

    I am running on MacOS High Sierra(10.13.6). I have mysql installed with homebrew.

    From looking through other posts about this I need to run an otool -L libqsqlmysql.dylib.

    When I do that I get the following:

    	libqsqlmysql.dylib (compatibility version 0.0.0, current version 0.0.0)
    	@rpath/QtSql.framework/Versions/5/QtSql (compatibility version 5.11.0, current version 5.11.1)
    	@rpath/QtCore.framework/Versions/5/QtCore (compatibility version 5.11.0, current version 5.11.1)
    	/System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration (compatibility version 1.0.0, current version 1.0.0)
    	/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
    	/usr/local/mysql/lib/libmysqlclient.20.dylib (compatibility version 20.0.0, current version 20.0.0)
    	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 307.5.0)
    	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.50.2)

    Homebrew installed mysql here


    which contains:

    libmysqlclient.21.dylib	libmysqlharness.a	libmysqlservices.a
    libmysqlclient.a	libmysqlharness.dylib	mysqlrouter
    libmysqlclient.dylib	libmysqlrouter.1.dylib	pkgconfig
    libmysqlharness.1.dylib	libmysqlrouter.dylib	plugin

    From what I've read I need to run a install_name_tool command with the '-change' flag. However , if that is what I need to do, I am not sure what I need to change to what. Can anyone offer any advice?

    [edit: Fixed coding tags SGaist]

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You are right, this question has been asked already a high number of time and answered also on this forum just as much.

    You need to change the path pointing to the MySQL dylib and change it to the one you have on your system.

  • Thanks for fixing my coding flags. That was my first time posting and It and left for work but then checked it on mobile and realized how horrible it looked and couldn't figure out how to fix them on mobile.

    So is the command I am looking for:

    install_name_tool -change /usr/local/mysql/lib/libmysqlclient.20.dylib /usr/local/Cellar/mysql/8.0.15/lib/libmysqlclient.dylib libqmysql.dylib

  • Lifetime Qt Champion

    No problem, they can be tricky.

    That's the correct line indeed.

  • @SGaist Oh great! It's working! Thank you so much!

  • Lifetime Qt Champion

    You're welcome !

    Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

  • @SGaist Sure thing;

    Also, so if anyone else comes across this with a similar issue, i should mention that my command was somewhat off, but barely. The exact command was

    install_name_tool -change /usr/local/mysql/lib/libmysqlclient.20.dylib /usr/local/Cellar/mysql/8.0.15/lib/libmysqlclient.dylib libqsqlmysql.dylib

Log in to reply