Backup and restore initialization of MySQL database in C #

Source: Internet
Author: User

//perform the CREATE database operation This. Getexecute (G_con,"CREATE database if not exists newdb"); This. sqladdress ="- H"+ IP +"- u"+ User +"- P"+ Password +"newdb";//Backup of the databasePrivate voidBtn_dump_click (Objectsender, EventArgs e) {    using(SaveFileDialog SFD =NewSaveFileDialog ()) {sfd. Filter="database File |*.sql"; SfD. FilterIndex=0; SfD. Restoredirectory=true; SfD. FileName="BackUp"+ DateTime.Now.ToString ("YYYYMMDDHHMMSS") +". SQL"; if(SFD. ShowDialog () = =System.Windows.Forms.DialogResult.OK) {stringFilePath =SFD.            FileName; stringcmd ="mysqldump"+ sqladdress +"> \ ""+ FilePath +"\""; stringresult =runcmd (CMD); if(result.) Trim () = ="") {MessageBox.Show ("database backup succeeded!","CMS", MessageBoxButtons.OK, messageboxicon.information); }            Else{MessageBox.Show (result,"CMS", MessageBoxButtons.OK, messageboxicon.information); }                  }    }}//Restoring a database//Restoring a databasePrivate voidBtn_import_click (Objectsender, EventArgs e) {    if( This. Tb_Path.Text.Trim () = ="") {MessageBox.Show ("Please select the file you want to recover!","CMS", MessageBoxButtons.OK, messageboxicon.information); return; }    //This . Getexecute (G_con, "CREATE database if not exists clothes");    stringFilePath = This. Tb_Path.Text.Trim (); stringcmd ="MySQL"+ sqladdress +"< \ ""+ FilePath +"\""; stringresult =runcmd (CMD); if(result.) Trim () = ="") {MessageBox.Show ("database recovery is successful!","CMS", MessageBoxButtons.OK, messageboxicon.information); }    Else{MessageBox.Show (result,"CMS", MessageBoxButtons.OK, messageboxicon.information); }}//command-line OperationsPrivate stringRuncmd (stringcommand) {    //Example ProcessProcess p =NewProcess (); p.StartInfo.FileName="Cmd.exe";//determine the program nameP.startinfo.arguments ="/ C"+ command;//determine the program command lineP.startinfo.useshellexecute =false;//use of the shellP.startinfo.redirectstandardinput =true;//REDIRECT inputP.startinfo.redirectstandardoutput =true;//REDIRECT outputP.startinfo.redirectstandarderror =true;//REDIRECT output errorP.startinfo.createnowindow =true;//Setting the display windowP.start ();//xxp.standardinput.writeline (command); //You can also enter the command in the line in this wayP.standardinput.writeline ("Exit");//add exit or the next line of code//p.WaitForExit (); //P.close (); //return P.standardoutput.readtoend (); //output out stream get command line result Fruit    returnp.standarderror.readtoend ();}

Backup and restore initialization of MySQL database in C #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.