Reputation: 2733
In my experience: the way to access mysql's database , i should access mysql-server firstly and then access database..But if want to access sqlite's database, i can access database file directly , just by a file(.db), so easy..
My question: can i access mysql database like sqlite ? Thank you!
The way to access mysql as follow:
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("demo");
db.setUserName("root");
db.setPassword("root1");
if(db.open()) {
qDebug("Make it");
} else {
qDebug("Sorry");
}
the way to access sqlite as follow:
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("chat.db");
Upvotes: 0
Views: 497
Reputation: 812
In your particular position you cannot access it in the same manner. As Adrian mentioned, SQL Lite is an embedded database, meaning it authenticates differently from a server-client model of MySQL.
Because the MySQL database is not local to the device, you must then use a MySQL user to connect to it. Otherwise, you pose a large security risk, as anyone with the server information could connect using the same string you’d want to connect with.
Upvotes: 1
Reputation: 58645
I assume you mean you want ot use MySQL as an Embedded Database.
If so, you should read here: http://www.mysql.com/oem/
Upvotes: 1