0

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?

4
  • there is no path to be entered the databse name is mydb Commented Mar 5, 2022 at 10:50
  • @nbk only if you want to use the default location Commented Mar 5, 2022 at 11:06
  • @Mark: No - If you want the database files lying on another directory then you have to specify it in the mysql config, not when you're doing a connection to a db (not matter if it is Qt or anything other) Commented Mar 5, 2022 at 11:46
  • in the database name is not possible to9 define the location, yyou can only change the my.cnf to redirect the location. try it pleas Commented Mar 5, 2022 at 13:21

1 Answer 1

1

mysql does not locate database using path, you have to specify the database name instead

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.