I’m trying to set up my embedded Linux
machine as a MySQL client, in order to connect to a external MySQL
server (running on a remote machine). sqlite
is not an option.
I understand, thanks to Basile Starynkevitch that I have to use libmysqlclient
(because that is the only library to run such a connection and dealing with the MySQL client/server protocol on the client side).
Qt stats that:
You need the MySQL header files and as well as the shared library libmysqlclient.so. Depending on your Linux distribution you may need to install a package which is usually called “mysql-devel”.
Did someone did this and can point out to the right package?
Advertisement
Answer
I ended up doing the following:
Installing MySQL on my embedded Linux and tested it with
mysql --host=1.2.3.4 --user=Foo --password=FooPass testdb
When an MySQL server is runing on 1.2.3.4.
I recompiled Qt with the
-sql-mysql
option, so the new compiled version will include Qt MySQL plugin.Test if Qt MySQL plugin is supported with the next code:
QStringList driverslist = QSqlDatabase::drivers(); QString str; foreach (str, driverslist) { qDebug() << str }
Expected output is:
QMYSQL3 QMYSQL
Test that driver loaded as expected with the next code:
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName("1.2.3.4"); db.setDatabaseName("TestDB"); db.setUserName("Foo"); db.setPassword("FooPass"); bool ok = db.open(); if(ok) { // "Connected" }