System: Windows 7Qt Version: 4.8.5Qt Creator version: 2.8.0 installation path: Qt---D:\Qt4.8.5Qt Creator, D:\Qtcreator-2.8.0mingw, d:\m Ingw 1. Configuring environment variables: to the system variables, advanced environment variable, properties, My Computer, edit path, add: My Computer's installation road ;D: \qt4.8.5\bin;d:\ Qtcreator-2.8.0\bin;d:\mingw\bin OK; to reopen a new CMD window if you have already opened CMD before configuring the environment variable in order for the environment variables to take effect. 2. Download MySQL official website www.mysql.com download, the file name of the non-installation package is similar to this format: Mysql-5.5.29-win32.zip only need lib and include in MySQL, extract to d: 3. Download mingw-utils-0.3.tar.gz extract, the bin folder inside the Reimp.exe copy to D:\mingw\bin directory, do not copy also line, call Reimp manually add absolute path. 4. Compile driver to open cmd, execute the following command: (1) Convert libmysql format cd d:\mysql\libreimp -d libmysql.libdlltool -k &NBSP;-D&NBSP;LIBMYSQL.DEF&NBSP;-L&NBSP;LIBMYSQL.A (2) compiling QT mysql driver cd d:\qt4.8.5\src\plugins\sqldrivers\ mysqlqmake "Config+=release" -o Makefile "Includepath+=d:/mysql/include" "libs+=d:/ MYSQL/LIB/LIBMYSQL.A " mysql.promingw32-makeqmake " Config+=debug " -o Makefile " Includepath+=d:/mysql/include " " LIBS+=D:/MYSQL/LIB/LIBMYSQL.A " mysql.promingw32-make 5. After the copy MySQL driver compilation is complete, open the D:\Qt4.8.5\src\plugins\sqldrivers\mysql directory, you can see the release and Debug directories, respectively, from the release and debug directory copy the following 4File to D:\qt4.8.5\plugins\sqldrivers:qsqlmysql4.dlllibqsqlmysql4.aqsqlmysqld4.dlllibqsqlmysqld4.a 6. Copy MySQL dynamic library (important) (1) Native run copy D:\mysql\lib\libmysql.dll file to d:\qt4.8.5\bin (2) Publish application without MySQL computer, to publish the application, To follow the Libmysql.dll piece publish, with the application sibling directory. 7. Test MySQL availability join the MySQL service already exists, then write the following code test: (1). Test for driver Qstringlist driverlist = qsqldatabase:: Drivers (); qdebug () << driverList; operation result: ("Qsqlite", "QMYSQL3", "Qmysql", "QODBC3", "Qodbc")? if present qmysql and QMYSQL3 are correct (2). Test if MySQL is available qsqldatabase db = qsqldatabase::adddatabase ("Qmysql"); db.setdatabasename ("Testsql"); bool ok = db.open (); qdebug () << ok; operation result: True true to indicate successful connection
MySQL Driver: http://download.csdn.net/detail/u012963417/8027075
http://blog.csdn.net/u012963417/article/details/37773531
MySQL driver for compiling QT under Windows