You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac OS Catalina下编译QT MySQL驱动遇问题求助

Fixing "QMYSQL driver not loaded" on Mac Catalina with Qt 5.14.2

Hey there, let's work through this MySQL driver issue step by step— I've been stuck on this exact problem before, so I know how frustrating it can be when you're just trying to learn and hit a roadblock like this. Let's break it down simply:

First, Let's Understand the Root Problem

Qt's online installer doesn't ship with the MySQL driver pre-compiled, so we need to build it ourselves. Your earlier attempts failed because you were working in the wrong directory and using incorrect qmake commands. Let's fix that.

Step 1: Install Qt's Source Code Component

First, you need the Qt source files to compile the driver. Since you used the online installer:

  • Open the Qt Maintenance Tool (it's in your Qt installation folder: /Users/Edward/Qt/MaintenanceTool.app)
  • Select "Add or Remove Components"
  • Expand the Qt 5.14.2 section, find and check the Sources option, then click "Apply" to install the source code.

Step 2: Navigate to the Correct MySQL Driver Source Directory

Forget the /plugins/sqldrivers folder you were using earlier— that's where compiled drivers go, not where we build them. Head to the source code's MySQL driver folder instead:

cd /Users/Edward/Qt/5.14.2/Src/qtbase/src/plugins/sqldrivers/mysql

Step 3: Set Up Your Environment for Qt's qmake

Make sure you're using the qmake that comes with your Qt 5.14.2 installation (not a system-wide one). First, check which qmake your terminal is using:

which qmake

If it doesn't show /Users/Edward/Qt/5.14.2/clang_64/bin/qmake, add Qt's bin folder to your PATH temporarily:

export PATH=/Users/Edward/Qt/5.14.2/clang_64/bin:$PATH

Step 4: Run qmake with the Correct MySQL Path

Your earlier qmake command was missing two key things: pointing to the mysql.pro file, and using the exact path to your MySQL installation (not just /usr/local). Run this command:

qmake MYSQL_PREFIX=/usr/local/mysql-8.0.19-macos10.15-x86_64 mysql.pro

This tells qmake where your MySQL headers and libraries are located. If you get no errors here, you're on the right track!

Step 5: Compile and Install the Driver

Now compile the driver with make, then install it to Qt's plugin folder:

make
make install

Wait for the compilation to finish— it might take a minute or two. Once done, the compiled libqsqlmysql.dylib file will automatically be copied to /Users/Edward/Qt/5.14.2/clang_64/plugins/sqldrivers.

Step 6: Verify the Driver Works

Restart Qt Creator, then create a simple test project to check if the driver loads:

#include <QCoreApplication>
#include <QSqlDatabase>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    qDebug() << "Available drivers:" << QSqlDatabase::drivers();
    return a.exec();
}

Run this— you should now see QMYSQL and QMYSQL3 in the list of available drivers.

Quick Troubleshooting Tips

  • If you get a "cannot verify developer" error when running your app: Go to System Preferences > Security & Privacy, and click "Allow Anyway" for the driver file.
  • Double-check that your MySQL installation is x86_64 (same as Qt's clang_64 build)— your MySQL 8.0.19 version for macOS 10.15 is correct here.
  • You don't need the MySQL Connector/C++ you installed earlier— Qt's driver uses MySQL's client library directly, so that component can be ignored for this process.

内容的提问来源于stack exchange,提问作者EdBatt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 14:52:38