Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt Mac version doesn't have file libqsqlmysql.dylib



  • Hi all,

    I am developing an app connect to database use MySQL, this is my code

        QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
        db.setHostName("localhost");
        db.setUserName("root");
        db.setPassword("");
        db.setDatabaseName("user_temp");
    

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

    I search for solution with this command:

    install_name_tool -change /usr/local/mysql/lib/libmysqlclient.21.dylib /usr/local/mysql-8.0.17-macos10.14-x86_64/lib/libmysqlclient.21.dylib /Users/macbook/Qt5.13.0/5.13.0/clang_64/plugins/sqldrivers/libqsqlmysql.dylib
    

    But It got error:

    error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: can't open file: /Users/macbook/Qt5.13.0/5.13.0/clang_64/plugins/sqldrivers/libqsqlmysql.dylib (No such file or directory)
    

    I check sqldrivers folder this is I have:
    0_1567225841113_Screen Shot 2019-08-31 at 11.29.35 AM.png

    It seem miss libqsqlmysql.dylib file
    So, how can I get this file to run?
    This is my info:
    Qt: 5.13.0
    MacOS: 10.14.6

    Thank you


  • Lifetime Qt Champion

    Hi,

    The most simple would be to build the plugin following the documentation.



  • Hi @SGaist
    I tried to build plugin as document with these command

    qmake -- MYSQL_PREFIX=/usr/local
    make sub-mysql
    

    but It seem incorrect syntax for qmake because I got these errors:
    0_1567268976984_Screen Shot 2019-08-31 at 11.29.14 PM.png

    and

    macbooks-MBP:sqldrivers macbook$ make sub-mysql
    make: *** No rule to make target `sub-mysql'.  Stop.
    

    This is my qmake version:

    macbooks-MBP:sqldrivers macbook$ qmake -version
    QMake version 3.1
    Using Qt version 5.13.0 in /Users/macbook/Qt5.13.0/5.13.0/clang_64/lib
    

    Did I miss anything, or i have to install more components?

    Thank again!


  • Lifetime Qt Champion

    Looks like you didn't install the sources, did you ?



  • Hi @SGaist,
    I have checked my folder, when I run command in Src, qmake -- MYSQL_PREFIX=/usr/local seem work fine
    but when I run
    make sub-mysql
    got error

    make: *** No rule to make target `sub-mysql'.  Stop.
    

    I tried to edit rerun qmake with path MYSQL_PREFIX=/usr/local/sql
    Error still exists, and this if my folder structure0_1567352396749_Screen Shot 2019-09-01 at 10.39.48 PM.png
    So what is incorrect here?


  • Lifetime Qt Champion

    Did you saw any error when calling qmake ?

    From the looks of it, I would have thought that your MySQL installation is rather in the mysql subfolder.



  • Hi @SGaist,
    I think not.
    Let make it easy, I'll show you all steps and log for this issue:

    1. In uninstall mysql and Qt from my MacBook
    2. I install mysql through file "mysql-8.0.17-macos10.14-x86_64.dmg" downloaded from mysql home page. As I know, this is latest release version of mysql.
      Installation success! Then I have 2 folder in /usr/local/
      /mysql/
      /mysql-8.0.17-macos10.14-x86_64/
    3. I install Qt 5.13.0 through file "qt-opensource-mac-x64-5.13.0.dmg", I installed all components, and it success
    4. I cd to Qt5.13.0/5.13.0/Src/qtbase/plugins/sqldrivers/ and run command:
      "qmake -- MYSQL_PREFIX=/usr/local/mysql"
      and I got this log
      0_1567401152808_Screen Shot 2019-09-02 at 11.36.46 AM.png

    then I run
    make sub-mysql
    and got this error
    0_1567400253123_Screen Shot 2019-09-02 at 11.37.22 AM.png

    I searched in Internet and in topic https://forum.qt.io/topic/99565/error-to-build-the-qmysql-plugin-on-macos-high-sierra/8

    I have command:
    configure -sql-mysql MYSQL_PREFIX=/usr/local/mysql

    After running, I got this log
    0_1567400409115_Screen Shot 2019-09-02 at 11.41.48 AM.png

    It seem Qt had driver mysql, then I go back Qt5.13.0/5.13.0/Src/qtbase/plugins/sqldrivers/
    and try to run make sub-mysql, now no error appears and I have this log:
    0_1567401426059_Screen Shot 2019-09-02 at 12.16.36 PM.png

    It seem ok, but in folder Qt5.13.0/5.13.0/clang_64/plugins/sqldrivers/, there is still no file libqsqlmysql.dylib.
    And I run app still got error
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
    Are there anything wrong here?
    Thank @SGaist


  • Lifetime Qt Champion

    In the first case, based on the summary, MySQL has not been found since the MySql line clearly says no, hence the error you have after. As to why it failed to find it, take a look at the test logs.

    As for the seconde case, you have your build of Qt installed in /usr/local/Qt-5.13.0. You will find there the MySQL plugin.



  • I try make install as log, but got error
    clang: error: no such file or directory: '/Users/macbook/Qt5.13.0/5.13.0/Src/qtbase/lib/libqtpcre2_debug.a'
    make[4]: *** [../../lib/QtCore.framework/QtCore_debug] Error 1
    make[3]: *** [debug-install] Error 2
    make[2]: *** [sub-corelib-install_subtargets] Error 2
    make[1]: *** [sub-src-install_subtargets] Error 2
    hmm, it seem be hard, I think qt should provide more detail direction to install Mysql plugin. I saw many topics on Forum about this issue, but still can not find correct one for my case, thank again @SGaist


  • Lifetime Qt Champion

    I suggested to look at the test logs that are generated when you called qmake in the plugin folder. There you'll find what went wrong.

    Note that since you have full Qt build with the MySQL plugin enabled, you can also use that one.



  • Hi, @SGaist ,
    Finally, it's done for me, but it takes time too much, I have look at many topics to find out solution for this. I think we should have a big topic to collect common issues + solution for each, it would reduce time for developer to search and supporter to answer.
    Thank you for your support.
    Between, I created a topic to give some instructions to create Mysql on Mac device at: https://forum.qt.io/topic/106565/mysql-qt-create-plugin-mysql-for-qt-on-mac, if you have time, please take a look at it, thanks.


Log in to reply