After spending a quite a bit of time to find the solution of this often-occurring
QMYSQL driver not loaded problem mainly after installing Qt installation in a new software environment, So I thought I am going to share my best practice to fix this issue.
I wasn’t able to establish database connection even if I received the list of available drivers:
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QPSQL
QSqlDatabase: QMYSQL driver not loaded
The following simple method helps to fix the problem.
On OSX system just simple install or re-install mysql using the flowing command. I usually prefer Homebrew as it fulfils most my requirements and using MacPort when I really no other options available.
$ brew install mysql
then place the following libmysqlclient.18.dylib file to the path below:
On different Linux distributions I usually apt install or yum install the MySQL package basically the only thing I need to make sure that place the libmysqlclient.18.dylib file to the following path:
This method solves the QMYSQL driver not loaded issue and allows me to establish database connection, it might work on Windows system as well, however I had not opportunity to try before.
Please, let me know if this method also working for you by dropping a line.