开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜