With this code:

db = QtSql.QSqlDatabase.addDatabase('QMYSQL') db.setHostName('localhost') db.setUserName('root') db.setPassword('1234') db.setDatabaseName('test') db.open() print(db.lastError().text()) 

The console displays the following:

 python gui.py QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7 Driver not loaded Driver not loaded 

The qsqlite.dll, qsqlmysql.dll, qsqlodbc.dll, qsqlpsql.dll libraries exist and are located in the

C: \ Python \ Lib \ site-packages \ PyQt5 \ Qt \ plugins \ sqldrivers

I use Windows 10 x64, Python 3.6.1, PyQt 5.8, MySql 5.7.

This question has already been asked here , but the solution that it contains, my problem is not solved.

What should I do to establish a connection with the database?

  • one
    Possible duplicate question: PyQt MySql driver not loaded - Sergey Gornostaev
  • The solution given in the question above did not help me. - Ls Ds

1 answer 1

To connect, you need to add the full path to / MySQL / lib to the variable variables in the PATH variable.

In my case, the full path looks like this:

C: \ Program Files (x86) \ MySQL \ MySQL Server 5.7 \ lib

Then, restart or log out for this addition to take effect, that's what I did, and what the solution was.