PyQt5 Error connection to Mysql "Driver not loaded"

0

I did not manage to solve this error that appears to me when trying to connect to a Mysql database with PyQt5

Instruction used:

from PyQt5.QtSql import QSqlDatabase, QSqlQuery, QSqlTableModel
from PyQt5.QtWidgets import QTableView, QApplication
import sys


def dbcon():
    db = QSqlDatabase.addDatabase('QMYSQL')
    db.setHostName('localhost')
    db.setDatabaseName('db_librowad')
    db.setUserName('root')
    db.setPassword('12345')
    ok = db.open()
    if not ok: print(db.lastError().text())
    # else: print("connected")
    query = QSqlQuery(db)
    query.exec_('SELECT * FROM tbl_Customers')


if __name__ == '__main__':
    app = QApplication(sys.argv)
    dbcon()

Error Message

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
Driver not loaded Driver not loaded
QSqlQuery::exec: database not open
Presione una tecla para continuar . . .
    
asked by Patrick Arguello 23.11.2018 в 15:27
source

1 answer

0

The solution I found was simple, downloading the dll file, from this link libmysql and placing it in the same folder where I have this .py file of connection to the MYSQL database. Obs. The operating system you used is W7.

    
answered by 26.11.2018 в 00:26