Creating mysql driver in mac
Unsolved
General and Desktop
-
Hi Team,
I am very new to the qt. In a recent project I was needed to connect a macos desktop app with mysql database. I have faced several issues. While configuring the driver, I followed multiple threads to search. I am trying here to put all my findings in a single place. Lets Start point wise.- Download mysql with arm 64 architecture from oracle website.
- I have used Qt 6.5.3, so assuming that you have installed it from Qt online installer and your Qt path in macOs is /User/<username>/Qt.
- I am assuming the mysql path is /usr/local/mysql.
- Create a folder anywhere I have used /User/<username>/build-sqldrivers. Created using command "mkdir build-sqldrivers".
- Navigate inside the folder using cd build-sqldrivers.
- Please install ninja using brew install ninja.
- Use below command to create the driver:
/Users/user/Qt/6.5.3/macos/bin/qt-cmake -G Ninja /Users/user/Qt/6.5.3/Src/qtbase/src/plugins/sqldrivers DCMAKE_INSTALL_PREFIX=/Users/user/Qt/6.5.3/macos -DMySQL_INCLUDE_DIR="/usr/local/mysql/include/" -DMySQL_LIBRARY="/usr/local/mysql/lib/libmysqlclient.24.dylib" -DCMAKE_OSX_ARCHITECTURES="arm64" - Next run the below command :
sed -i -e 's/-arch x86_64/-arch arm64/g' /Users/user/build-sqlrivers/build.ninja - Next run :
cmake --build . - In the next step run install :
cmake --install . - If all the above steps are executed successfully you can find the library files in Qt/6.5.3/macos/plugin/sqldrivers, however if you run the qt code, you may face the same error. If the error persist, please follow the below steps.
- Check for the architecture of QtCore and libqsqlmysql.dylib, using the below commands , both should be same for me it is arm 64.
** command 1 "file /Users/user/Qt/6.5.3/macos/lib/QtCore.framework/QtCore" without quote.
** command 2 "file /Users/honeysharma/Qt/6.5.3/macos/plugins/sqldrivers/libqsqlmysql.dylib" without quote. - Please check your code again it should now resolve the architecture error.
- Last step, please link the sql driver from mysql to /Qt/macos/plugin/sqldrivers using below command.
** ln -s /usr/local/mysql/lib/libmysqlclient.24.dylib /Users/user/Qt/6.5.3/macos/lib/libmysqlclient.24.dylib