Qt 6.2.0, Ubuntu 21.10.
Usually MariaDb
stores database under /var/lib/mysql/
directory.
I can connect to my own database using this working code:
_db = QSqlDatabase::addDatabase("QMYSQL", "machines");
_db.setHostName("localhost");
_db.setDatabaseName("mydb");
_db.setUserName("user");
_db.setPassword("password");
qDebug() << _db.open(); // true
I copied the database to another location:
$ sudo cp -r /var/lib/mysql/mydb /home/mark/mydir/
Changing the database name to:
_db.setDatabaseName("/home/mark/mydir/mydb");
leads to fail when open()
is called.
The error is:
QMYSQL: Unable to connect", "Unknown database 'home/mark/mydir/mydb'
What is the correct syntax do specify a different path?