0

How can I dump some of the tables from my mysql database into an sql file in C#? Is there a class which does this?

UPDATE: just wanted to mention to DO NOT USE mysqldump, because this application will be installed on many computers and the mysql folder could be on different places.

2 Answers 2

2

Dotconnect for mysql might have this feature, but I don't know about the free version.

Otherwise you could just invoke the mysqldump utility and do something like this:

public void DumpMySQLDb(string user, string password, string database, string outputFile) {
  var commandLine = string.Format("mysqldump --user={1}--password={2} --hex-blob --databases {3}",
     user, password, database)
  var process = new Process();
  process.StartInfo = new ProcessStartInfo {
      FileName = "cmd",
      Arguments = string.Format( "/c \"{0}\" > {1}", commandLine, outputFile )
  };
  process.Start();
}
Sign up to request clarification or add additional context in comments.

2 Comments

can the mysqldump be used without the path in front?
but it wont't. Anyway thanks for the answer. Appreciate it. I think I'm going to build a dump class, read the tables and data and write to file.
0

I built up the sql string table by talbe in the end.

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.