It is better to explain the classification of the database separately. However, as a skill, it is hard to determine how to classify the database.
Backup method:First, obtain the installation path of the MySQL program through the registry. If it is version 5.0, it is:
var registerLocation = @"Software\MySQL AB\MySQL Server 5.0";
var key = Registry.LocalMachine.OpenSubKey(registerLocation);
if (key != null)
{
var location = key.GetValue("Location").ToString();
}
After obtaining the path, create a new process and prepare to start the backup. The specific details are annotated with the code.
VaR proc = new process ();
// Use the following command line to run cmd.exe
Proc. startinfo. filename = "cmd.exe ";
// Disable System Shell startup
Proc. startinfo. useshellexecute = false;
// Set the working directory to location + @ "bin"
// Because mysqldump is used for backup, and mysqldump is in the directory location + @ "bin"
Proc. startinfo. workingdirectory = location + @ "bin ";
// For mysqldump parameters, refer to the notes on the MySQL official website. The format method is used here.
// What does each of the obtained command parameters mean? It is literally easy to understand, not to explain, ^_^
Proc. startinfo. arguments = string. format ("mysqldump.exe -- default-character-set = utf8-H {0}-U {1}-P {2} {3 }>{ 4}", server, user, PWD, database, backupfile );
// Do not create a window, which is equivalent to hiding the interface
Proc. startinfo. createnowindow = true;
// The following two sentences are used for debugging purposes.
Proc. startinfo. redirectstandardinput = true;
Proc. startinfo. redirectstandardoutput = true;
// Start the backup.
Proc. Start ();
// Wait until the backup is complete
Proc. waitforexit ();
// Close the process
Proc. Close ();
The backup is completed in a few steps.
Restoration method:In the following example, only mysql.exe needs to be modified. The specific parameter-force indicates forced restoration. Others are clear and not explained.
proc.StartInfo.Arguments = string.Format("mysql.exe --force -h {0} -u {1} -p{2} {3} < {4}",
server,user,pwd,database,restoreFile);
No extra code is written. O (nobody _ Nobody) O Haha ~