配置mysql驱动
- 官方网址
https://doc.qt.io/qt-6.2/sql-driver.html
- 官网文档解释
Embedded MySQL Server
The MySQL embedded server is a drop-in replacement for the normal client library. With the embedded MySQL server, a MySQL server is not required to use MySQL functionality.
To use the embedded MySQL server, simply link the Qt plugin to libmysqld instead of libmysqlclient. This can be done by adding -DMySQL_LIBRARY=<path/to/mysqld/>libmysqld.<so|lib|dylib> to the configure command line.
Please refer to the MySQL documentation, chapter “libmysqld, the Embedded MySQL Server Library” for more information about the MySQL embedded server.
How to Build the QMYSQL Plugin on Unix and macOS
You need the MySQL / MariaDB header files, as well as the shared library libmysqlclient.<so|dylib> / libmariadb.<so|dylib>. Depending on your Linux distribution, you may need to install a package which is usually called “mysql-devel” or “mariadb-devel”.
Tell qt-cmake where to find the MySQL / MariaDB header files and shared libraries (here it is assumed that MySQL / MariaDB is installed in /usr/local) and build:
mkdir build-sqldrivers
cd build-sqldrivers
qt-cmake -G Ninja <qt_installation_path>/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DMySQL_INCLUDE_DIR="/usr/local/mysql/include" -DMySQL_LIBRARY="/usr/local/mysql/lib/libmysqlclient.<so|dylib>"
cmake --build .
cmake --install .
- 自定义修改整理后如下
ln -s /opt/Qt/Tools/Ninja/ninja /usr/bin/ninja-build
mkdir build-sqldrivers
cd build-sqldrivers
/opt/Qt/6.*/gcc_64/bin/qt-cmake -G Ninja /opt/Qt/6.*/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=/opt/Qt/6.2.4/gcc_64 -DMySQL_INCLUDE_DIR="/usr/include/mysql" -DMySQL_LIBRARY="/lib64/libmysqlclient.so"
cmake --build .
cmake --install .