There are quite a few questions/answers relating to this topic but I have tried all the posted solutions:
System Info :
Ubuntu Gnome 16.10 x86-64
MYSQL Version:
mysql Ver 14.14 Distrib 5.7.15, for Linux (x86_64) using EditLine wrapper
Note: Each attempt ends up with this error message
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
Tried:
Installing Packages for QT 4:
apt-get install libqt4-sql-mysql
Installing Packages for QT 5:
apt-get install libqt5sql5-mysql
Removing and installing libmysqlclient-dev
$ sudo apt-get purge libmysqlclient-dev
$ sudo apt-get install libmysqlclient-dev
Tried creating symlink as shown below:
#locate libmysqlclient file
$ locate libmysqlclient
/usr/lib/x86_64-linux-gnu/libmysqlclient.so.20
/usr/lib/x86_64-linux-gnu/libmysqlclient.so.20.3.2
/usr/share/doc/libmysqlclient20
/usr/share/doc/libmysqlclient20/NEWS.Debian.gz
/usr/share/doc/libmysqlclient20/changelog.Debian.gz
/usr/share/doc/libmysqlclient20/copyright
/var/cache/apt/archives/libmysqlclient20_5.7.15-0ubuntu2_amd64.deb
/var/lib/dpkg/info/libmysqlclient20:amd64.list
/var/lib/dpkg/info/libmysqlclient20:amd64.md5sums
/var/lib/dpkg/info/libmysqlclient20:amd64.shlibs
/var/lib/dpkg/info/libmysqlclient20:amd64.symbols
/var/lib/dpkg/info/libmysqlclient20:amd64.triggers
#cd to the dir, and create link
$ cd /usr/lib/x86_64-linux-gnu
$ sudo ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20 libmysqlclient_r.so
this one I just incase
$ sudo ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20 libmysqlclient_r.so
Contents of Plugin directory:
ll /opt/qt/QT-5.7/5.7/gcc_64/plugins/sqldrivers/
total 988
drwxrwxr-x 1 cx cx 84 Oct 17 15:58 ./
drwxrwxr-x 1 cx cx 504 Oct 17 15:58 ../
-rwxr-xr-x 1 cx cx 851008 Jun 10 11:10 libqsqlite.so*
-rwxr-xr-x 1 cx cx 75424 Jun 10 11:10 libqsqlmysql.so*
-rwxr-xr-x 1 cx cx 79368 Jun 10 11:10 libqsqlpsql.so*
Project Info:
Added to .pro file:
QT += sql
Code:
#include <QtSql>
#include <QSqlDriver>
#include <qsqldatabase.h>
#include <QSqlError>
#include <QPluginLoader>
#include <cstdio>
using namespace std;
//some irrelevant project code in between
QString rootPass = getRootPassword();
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
// db.setDatabaseName(DBName);
db.setUserName("root");
db.setPassword(rootPass);
if (!db.isValid()){
QSqlError err = db.lastError();
cout << endl << "!DB ERROR: "<< err.text();
cout.flush();
}
//qsqlerror err: unused4 : 21985
//qsqlerror err: unused3 : 2757134240 (2757134240)
if (db.open()){
//do things to database
}
else
{
cout << "error opening database" << endl;
}
In my project, I have tried:
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
and
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL3");
just in case, no luck
I have also copied the libmysqlclient.so
file to my plugins directory, also did not work (tried this incase of a library path missing,etc.)
I have no idea how to continue further, any suggestions would be helpful
Well the solution was not easy but it had to be done.
I had to recompile the driver!
use this as a guide.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.