开发者

backup mysql database from Qt C++

开发者 https://www.devze.com 2023-03-28 15:35 出处:网络
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\"

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

精彩评论

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