1. Error report, QSqlDatabase: QMYSQL driver not loaded
2. Reason
This problem is generally caused by the incompatibility of the MySQL driver that comes with qt and the installed MySQL. A lot of methods on the Internet are to directly recompile MySQL to replace the version, which is more troublesome. Finding and replacing the incompatible library directly here is feasible and time-saving.
3. Find libqsqlmysql.so
sudo find / -name libqsqlmysql.so
/usr/lib/x86_64-linux-gnu/qt4/plugins/sqldrivers/libqsqlmysql.so is the MySQL library
/opt/Qt5.12.2/5.12.2/gcc_64/plugins/sqldrivers/libqsqlmysql.so
and / opt / Qt5. 12.2 / Tools / QtCreator / lib / Qt / plugins / sqldrivers / libqsqlmysql.so is the library that comes with qt, the latter two are the same
4. View the libraries that libqsqlmysql.so depends on
Qt library is missing libmysqlclient.so.18
5. Download a libmysqlclient.so.18
https://launchpad.net/ubuntu/xenial/amd64/libmysqlclient18/5.6.25-0ubuntu1
6. Download and install
sudo dpkg -i libmysqlclient18_5.6.25-0ubuntu1_amd64.deb
Now running QtCreator finds that no more errors are reported, Qt can connect to the MySQL database normally