backup mysql database from Qt C++
mysqldump -uroot -pmysql test> C/backup/test.sql
If I run the command above in commandline, it will do a backup for my database "test"
Now, I tried to use the same command inside my Qt C++ code, but it did not work, while I can insert,delete,and update my "test" database ea开发者_开发百科sily with no problems.
anyhelp please.
You need to use ::system()
function to use mysqldump tool. You cannot create dump using SQL queries.
You can use QProcess class for this purpose too.
Here's an example:
QProcess dumpProcess(this);
QStringList args;
args << "-uroot" << "-pmysql" << "test";
dumpProcess.setStandardOutputFile("test.sql");
dumpProcess.start("mysqldump", args);
Note that your mysqldump tool should be in on any dir in PATH enviroment variable.
精彩评论