PDA

View Full Version : PyQt5:QMYSQL driver not loaded



RamrajCh
3rd January 2020, 03:20
Hi,
I got a problem on connecting database on my project.
I use PyQt5.QSqlDatabase for connecting but a error occured.


from PyQt5.QtSql import *

class Database():
def __init__(self,hostname,user,dbase,pword=""):
self.db=QSqlDatabase.addDatabase("QMYSQL")
self.db.setHostName(hostname)
self.db.setDatabaseName(dbase)
self.db.setUserName(user)
self.db.setPassword(pword)
ok = self.db.open()

mydb=Database("localhost","root","billingsys")


Error is:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7

ChrisW67
3rd January 2020, 06:57
You need to build and install the Qt MySQL database plugin before QT or PyQT5 can load it.
See here: QMYSQL for MySQL 4 and higher
(https://doc-snapshots.qt.io/qt5-5.14/sql-driver.html#qmysql-for-mysql-5-and-higher)

d_stranz
4th January 2020, 17:10
@Juliehannah: If you continue to post links to unrelated commercial web sites, I will report you as a spammer and ask for your username to be deleted. This is the only warning I'll give.

adarsh1783
28th March 2020, 09:58
Hi,
I got a problem on connecting database on my project.
I use PyQt5.QSqlDatabase for connecting but a error occured.


from PyQt5.QtSql import *

class Database():
def __init__(self,hostname,user,dbase,pword=""):
self.db=QSqlDatabase.addDatabase("QMYSQL")
self.db.setHostName(hostname)
self.db.setDatabaseName(dbase)
self.db.setUserName(user)
self.db.setPassword(pword)
ok = self.db.open()

mydb=Database("localhost","root","billingsys")


Error is:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7

Hi, I have ran into same problem.I have looked almost every link which is a suggested solution to this but most of them are about QT not PyQT and none of them worked for me anyway.

Did you find a solution to this ?? If so please help me.

I am using Windows 10 OS, PyQt5.14.1, MySQL 8.0.19, mysql-connector-python 8.0.19.

Please reply as soon as possible. I am stuck to this 2 last days. :(

Thanks

ChristianEhrlicher
28th March 2020, 15:24
As ChrisW67 already said you have to build the driver on your own. Follow the instructions in link ChrisW67 gave above.

adarsh1783
28th March 2020, 20:18
As ChrisW67 already said you have to build the driver on your own. Follow the instructions in link ChrisW67 gave above.

Correct me if I am wrong.
Those are for Qt not for PyQt5. They used qmake but there is no file with name as qmake.exe or qmake.py in PyQt5 folder.

I am using PyQt5 only not Qt.

Can you guide me about how to build and install MYSQL driver for PyQt5 in windows 10 ?

I did try to adding qsqlmysql.dll directly to ..Python37\Lib\site-packages\PyQt5\Qt\plugins\sqldrivers but that didn't work with error
QMYSQL: driver not loaded, available driver QSQLITE, QMYSQL, QMYSQL3, ...

I did find libmysql.dll and libmysql.lib in MYSQL SERVER folder but didn't find any link describing how to use them for PyQt5 in windows.

Thanks

ChristianEhrlicher
29th March 2020, 09:09
PyQt just uses the Qt libraries through a wrapper so I don't see why this should not apply to you...

adarsh1783
30th March 2020, 22:47
Correct me if I am wrong.
Those are for Qt not for PyQt5. They used qmake but there is no file with name as qmake.exe or qmake.py in PyQt5 folder.

I am using PyQt5 only not Qt.

Can you guide me about how to build and install MYSQL driver for PyQt5 in windows 10 ?

I did try to adding qsqlmysql.dll directly to ..Python37\Lib\site-packages\PyQt5\Qt\plugins\sqldrivers but that didn't work with error
QMYSQL: driver not loaded, available driver QSQLITE, QMYSQL, QMYSQL3, ...

I did find libmysql.dll and libmysql.lib in MYSQL SERVER folder but didn't find any link describing how to use them for PyQt5 in windows.

Thanks

I uninstalled PyQt5 5.14.1 and installed PyQt5 5.12.1 and everything work fine.