It is found that ‘qmmysql’ and ‘qmysql3’ have successfully appeared. Restart the programming tool and print again (QSqlDatabase. You can choose the appropriate path according to the relative path of the above path according to the installation location of anaconda. Take my computer as an example, paste the file to the following path:ĭ:\Anaconda\Anaconda\Lib\site-packages\PyQt5\Qt\bin First, find the libmysql.dll (this is the default path for MySQL installation, and the user-defined path will be found separately) in the path of C:// program files/MySQL/MySQL server 8.0/bin, and copy it. At the same time, these two files must be fully matched with the relevant pyqt version.įirst, open Anaconda prompt, enter the following command line, and adjust the python version to 5.12.1 (only this version comes with qsqlmysql.dll, other versions of this DLL are too difficult to find a matching one) pip install PyQt5=5.12.1Īfter this step, qsqlmysql.dll has been successfully installed in the relevant folder. The general idea is to add two DLL files: qsqlmysql.dll and libmysql.dll in pyqt related folder.
The author’s pyqt is installed in Anaconda environment, so the folder path to be found by the driver is special. This method can also get the specific part of the connection error.Ģ. Method 2: print error information print(self.DB.lastError().text()) Because under normal conditions, the output should be as follows:
You can use this method to solve the problem. If ‘qmmysql’ and ‘qmysql3’ are found missing in the driver, it indicates that the error is driver missing. Method 1: check the driver attached to pyqt print(QSqlDatabase.drivers()) Errors can be found in the following ways. However, sometimes the connection fails, and debug can’t point out the error clearly.
Self.DB.setPassword('') # Enter the password for your own database
Self.DB.setDatabaseName("school_club") # Enter the data table you want to access Miniconda3 Linux-s390x 64-bit (conda 4.10.Generally speaking, pyqt can connect to MySQL database in the following format: self.DB = QSqlDatabase.addDatabase('QMYSQL') Which does require administrator permissions. However, if you need to, you can install Miniconda system wide, Which does not require administrator permissions and is the most robust type of On Windows, macOS, and Linux, it is best to install Miniconda for the local user,
If your operating system is older than what is currently supported, you can find older versions of the Miniconda installers in our archive that might work for you.
Operating system: Windows 8 or newer, 64-bit macOS 10.13+, or Linux, including Ubuntu, RedHat, CentOS 7+, and others.License: Free use and redistribution under the terms of the EULA for Miniconda.