[SOLVED] QSqlDatabase: QMYSQL driver not loaded with QMYSQL driver available in OSX Mavericks
-
wrote on 26 Dec 2013, 15:39 last edited by
Hi all, I am having an issue with QMYSQL when open a project created in Qt4.7 in Qt5.2. In particular when connecting to the database, i get the following error:
@QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7@I am using Qt5.2 on OSX 10.9.1 (Mavericks). Have any of you had any similar issue? Thank you.
Mario
-
Hi,
Do you have MySql installed on Mavericks ? If so run otool -L on the qmysql.dylib plugin to see if everything is correct
-
wrote on 27 Dec 2013, 15:07 last edited by
hi, I have no qmysql.dylib in ~/Qt5.2.0/5.2.0/clang_64/plugins/sqldrivers so I did:
@otool -L libqsqlmysql.dylib@
I don't know if this is what you meant.The output is:
@libqsqlmysql.dylib:
libqsqlmysql.dylib (compatibility version 0.0.0, current version 0.0.0)
/opt/local/lib/mysql55/mysql/libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
/Users/ucmar/Qt5.2.0/5.2.0/clang_64/lib/QtSql.framework/Versions/5/QtSql (compatibility version 5.2.0, current version 5.2.0)
/Users/ucmar/Qt5.2.0/5.2.0/clang_64/lib/QtCore.framework/Versions/5/QtCore (compatibility version 5.2.0, current version 5.2.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)@Thanks.
-
You got the right name, sorry for the wrong direction. The output looks good. Can you post what error you have from the connection failure ?
-
wrote on 27 Dec 2013, 22:50 last edited by
So, I get a window with the text: "Driver not loaded Driver not loaded". The Application Output returns the following error:
@QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
QSqlQuery::exec: database not open@ -
and what does QSqlDatabase::lastError() return ?
-
wrote on 30 Dec 2013, 15:53 last edited by
That function seems to return this text: “Driver not loaded Driver not loaded”.
I am using the following error check:
@if (!db.open())
{
QMessageBox::critical(0, QObject::tr("Database Error"),
db.lastError().text());
}@ -
Just to be sure do you have this file:
/opt/local/lib/mysql55/mysql/libmysqlclient.18.dylib ?
-
wrote on 30 Dec 2013, 16:52 last edited by
Thanks for your hint. I didn't have it, and I also missed the folder "../mysql". I have just tried to copy it from another folder on my mac (a subfolder of a drupal local website), but my application still shoots the same error... :(
-
Since it's in /opt/ I would suspect it's a MacPort install of MySql.
If you have the same lib you can use install_name_tool to change the path in your libqsqlmysql.dylib
-
wrote on 31 Dec 2013, 01:17 last edited by
Thank you very much SGaist!!! I realized I had mistakenly created only the "../mysql" folder under "/opt/local/lib"! I have then fixed my problem by creating the complete folder path "../mysql55/mysql" as you suggested and copying the file libmysqlclient.18.dylib there. My Database connection is correctly working now! :D
Wish you a great 2014! Eheh
Mario
-
You're welcome !
All the same to you !
-
wrote on 27 Feb 2014, 02:15 last edited by
my os is windows 7 ,andI am having an issue with QMYSQL when open a project in Qt5.2. In particular when connecting to the database, i get the following error:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase :available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7 -
Hi foxgod,
Please have a look at the already numerous threads related to this problem with windows. This one is dedicated to OS X.
-
wrote on 2 Apr 2014, 15:38 last edited by
Hi guys,
I'm sorry to open this post again but I found this to be the thread that best approximates my situation.Basically I followed everything until here:
[quote author="SGaist" date="1388421018"]Just to be sure do you have this file:/opt/local/lib/mysql55/mysql/libmysqlclient.18.dylib ?[/quote]
I haven't used macports to install mysql, I used the "MMV MySQL Script":http://code.macminivault.com/
Do I need to create that folder in my directory structure and just copy the libmysqlclient.18.dylib there? Also, when did it become libmysqlclient.18.dylib :D Last time I checked you were still talking about libmysqlclient.dylib :SSorry guys, I've been looking for solutions for weeks now!
PS.: My "otool -L libqsqlmysql.dylib " looks like this:
libqsqlmysql.dylib:
libqsqlmysql.dylib (compatibility version 0.0.0, current version 0.0.0)
libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
/Users/sacdallago/Qt5.2.1/5.2.1/clang_64/lib/QtSql.framework/Versions/5/QtSql (compatibility version 5.2.0, current version 5.2.1)
/Users/sacdallago/Qt5.2.1/5.2.1/clang_64/lib/QtCore.framework/Versions/5/QtCore (compatibility version 5.2.0, current version 5.2.1)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0) -
wrote on 2 Apr 2014, 15:51 last edited by
P.P.S.: Looking around I found the 'libmysqlclient.18.dylib' file (in the folder '/usr/local/mysql-5.6.16-osx10.7-x86_64/lib/'), and I copied it to '/opt/local/lib/mysql55/mysql/'.
This didn't solve the problem, though :(Any other suggestions?
-
Hi and welcome to devnet,
The location of the library itself is not the key here. Use install_name_tool to update the path to point to your libmysqlclient.18.dylib
-
wrote on 5 Apr 2014, 14:22 last edited by
[quote author="SGaist" date="1396469393"]Hi and welcome to devnet,
The location of the library itself is not the key here. Use install_name_tool to update the path to point to your libmysqlclient.18.dylib[/quote]
Thanks for the suggestion SGaist! I still could't make it work after using install_name_tool, so I just switched to postgres, which worked out-of-the-box.
I will try to figure out how to make MySQL work when I won't have deadlines keeping me awake at night :S
Best regards!
-
Check both Qt's MySQL plugin and libmysqlclient with otool -L to ensure that everything can be found correctly
-
wrote on 11 Feb 2016, 13:29 last edited by Orbotron 2 Nov 2016, 13:31
Re: [SOLVED] QSqlDatabase: QMYSQL driver not loaded with QMYSQL driver available in OSX Mavericks
Just wanted to reply 2 years later to let people know that this solution still works on OSX if you download the offline installer qt-opensource for Mac OSX.
Thanks!
I ran otool on my libsqlmysql.dylib and it was pointing at
[dank:...clang_64/plugins/sqldrivers]$ otool -L libqsqlmysql.dylib libqsqlmysql.dylib: libqsqlmysql.dylib (compatibility version 0.0.0, current version 0.0.0) /opt/local/lib/mysql55/mysql/libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0) /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5) @rpath/QtSql.framework/Versions/5/QtSql (compatibility version 5.5.0, current version 5.5.1) ...
I install MySQL with Homebrew
[dank:...clang_64/plugins/sqldrivers]$ l /usr/local/lib/ | grep 18 drwxrwxr-x 32 root admin 1.1K Feb 10 18:49 .. drwxr-xr-x 3 dank admin 102B Nov 18 12:35 python2.7 lrwxr-xr-x 1 dank admin 52B Jan 29 13:11 utf8_and_gb18030.so -> ../Cellar/postgresql94/9.4.5/lib/utf8_and_gb18030.so [dank:...clang_64/plugins/sqldrivers]$ l /usr/local/lib/ | grep mysql lrwxr-xr-x 1 dank admin 20B Feb 8 08:21 lib -> /usr/local/mysql/lib lrwxr-xr-x 1 dank admin 50B Feb 8 08:15 libmysqlclient.20.dylib -> ../Cellar/mysql/5.7.11/lib/libmysqlclient.20.dylib lrwxr-xr-x 1 dank admin 43B Feb 8 08:15 libmysqlclient.a -> ../Cellar/mysql/5.7.11/lib/libmysqlclient.a lrwxr-xr-x 1 dank admin 47B Feb 8 08:15 libmysqlclient.dylib -> ../Cellar/mysql/5.7.11/lib/libmysqlclient.dylib lrwxr-xr-x 1 dank admin 38B Feb 8 08:22 libmysqld-debug.a -> /usr/local/mysql/lib/libmysqld-debug.a lrwxr-xr-x 1 dank admin 38B Feb 8 08:15 libmysqld.a -> ../Cellar/mysql/5.7.11/lib/libmysqld.a lrwxr-xr-x 1 dank admin 45B Feb 8 08:15 libmysqlservices.a -> ../Cellar/mysql/5.7.11/lib/libmysqlservices.a ...
so I ran
install_name_tool -change /opt/local/lib/mysql55/mysql/libmysqlclient.18.dylib /usr/local/Cellar/mysql/5.7.11/lib/libmysqlclient.20.dylib libqsqlmysql.dylib
to double check
[dank:...clang_64/plugins/sqldrivers]$ otool -L libqsqlmysql.dylib libqsqlmysql.dylib: libqsqlmysql.dylib (compatibility version 0.0.0, current version 0.0.0) /usr/local/Cellar/mysql/5.7.11/lib/libmysqlclient.20.dylib (compatibility version 18.0.0, current version 18.0.0) /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5) @rpath/QtSql.framework/Versions/5/QtSql (compatibility version 5.5.0, current version 5.5.1) @rpath/QtCore.framework/Versions/5/QtCore (compatibility version 5.5.0, current version 5.5.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/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
I feel the fact that it still says version 18.0.0 is weird but it works now for me