-
-
Notifications
You must be signed in to change notification settings - Fork 67
Open
Description
@thecodemonkey86 thanks to thecodemonkey86, I compile it in qt 6.6.1 successfully, this is my note.Hope can help you.
By the way, i install mysql8 on my windows 11.
- Copy mysql lib path and head path to other dir. Because I got some errors like
Permission deniedorNo such file or directory,so change it in a simple path.
复制 mysql 头文件和 lib 库到一个简单目录,避免玄学问题。
C:\Program Files\MySQL\MySQL Server 8.0\include -> D:\mysql\include
C:\Program Files\MySQL\MySQL Server 8.0\lib -> D:\mysql\lib
- Build qmysql.dll using cmake gui and cmake
cmake --build build --target install.
使用 cmake-gui 和 cmake 命令cmake --build build --target install构建 qmysql.dll。


- Copy driver from
C:\Program Files (x86)\QSQLiteDriverPlugins\plugins\sqldriverstoD:\Qt\6.6.1\mingw_64\plugins\sqldrivers
复制 qsqlmysql 驱动到 qt 插件目录。

- Try to print all
QSqlDatabase::drivers, But i found it is empty, and using ChatGpt, it tells me i need set plugins path.
打印看看是否有 mysql 驱动,如果找不到,把目录加进去,
QCoreApplication::addLibraryPath("D:/Qt/6.6.1/mingw_64/plugins");
qDebug() << QSqlDatabase::drivers();

6. Copy qsqlmysql.dll to project build path like build-opcTrans-Desktop_Qt_6_6_1_MinGW_64_bit-Release\sqldrivers.
复制qsqlmysql.dll 到 exe 输出目录下sqldrivers目录,没有建一个。

7. Copy libmysql.dll to project build path like build-opcTrans-Desktop_Qt_6_6_1_MinGW_64_bit-Release.
复制libmysql.dll 到 exe 输出目录下。

8. Try to connect db.
然后就可以试试了。
QCoreApplication::addLibraryPath("D:/Qt/6.6.1/mingw_64/plugins");
qDebug() << QSqlDatabase::drivers();
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("ip");
db.setPort(3306);
db.setDatabaseName("dbname");
db.setUserName("user");
db.setPassword("password");
bool ok = db.open();
if (ok){
qDebug() << "OK";
}
else {
QSqlError error = db.lastError();
qDebug()<<"error open database because"<< error.text();
}
Here are libmysql.dll。我自己编译的文件。
libmysql.zip
qsqlmysql.dll
sqldrivers.zip
Metadata
Metadata
Assignees
Labels
No labels