Qt 5.4.1 compiled MySQL driver, connect MySQL database

Source: Internet
Author: User

QT installed in the D:\Qt directory, the QT 5.4.1 connection MySQL database, found the following error

Qsqldatabase:qmysql driver not loadedqsqldatabase:available drivers:qsqlite qmysql qmysql QMYSQL3 qodbc
Go to the D:\Qt\Qt5.4.1\5.4\mingw491_32\plugins\sqldrivers directory and find out that there is a MySQL driver


Google a bit, it is said that the driver is satisfied with the dependency, not satisfied, need to recompile, then recompile it.

Download the 5.6 version of the 32-bit zip file to MySQL website and unzip it to D:\MYSQL-WIN32 (it must be 32-bit MySQL, otherwise the compilation will not pass).

Unzip the Qt5.4.1 zip source to G:\Qt\qt-everywhere-opensource-src-5.4.1.

Open MinGW command-line tool


Switch to QT source directory

CD G:\Qt\qt-everywhere-opensource-src-5.4.1\qtbase\src\plugins\sqldrivers\mysql\

Generate makefile

Qmake "Includepath+=d:\mysql-win32\include" "Libs+=d:\mysql-win32\lib\libmysql.lib"-O Makefile Mysql.pro
Compile

Mingw32-make

After a successful compilation, the MySQL driver file will be generated in G:\Qt\qt-everywhere-opensource-src-5.4.1\qtbase\plugins\sqldrivers.


Copy Qsqlmysql.dll and Qsqlmysqld.dll to D:\Qt\Qt5.4.1\5.4\mingw491_32\plugins\sqldrivers to replace the original file.

Then copy the D:\MySQL-Win32\lib\libmysql.dll to the C:\Windows directory.


This allows QT to connect to the MySQL database.





Qt 5.4.1 compiled MySQL driver, connect MySQL database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.