MySQL Backup migration--mysqldump (. NET call Mysqldump.exe mode)--(Resolve view embedding ungrateful error)

Source: Internet
Author: User
Tags mysql backup

The use of mysqldump backup and migration, I think a lot of people have used, the specific parameters are not introduced, the main talk here. NET calls mysqldump for backup and. NET call Mysql.exe to import data.

The use of the 5.1 version of Mysqldump.exe and Mysql.exe (5.5 version of the use, no test success)

This case is divided into two steps because it is necessary to resolve an error in the View Embedded view when importing.

The first step is to migrate only the table structure, views, stored procedures, functions, events, and so on. (Why this data is not together, because the view needs to add--extended-insert=false, so the data will be very slow, so it is divided into two-step guide.) )

stringStrerror =string. Empty;//executes cmd to get output information.
Process P=NewProcess (); p.StartInfo.FileName="Cmd.exe"; P.startinfo.redirectstandardinput=true; P.startinfo.useshellexecute=false; P.startinfo.redirectstandardoutput=true;//Get output stream//p.startinfo.redirectstandardinput = true;P.startinfo.redirectstandarderror =true;//Get error FlowP.startinfo.windowstyle=Processwindowstyle.hidden; P.startinfo.createnowindow=true; //In addition to data, table structure, views, stored procedures, functions, events are all exportedP.start (); P.standardinput.writeline ("C:"); P.standardinput.writeline ("CD C:\\Program Files (x86) \\MySQL\\MySQL Server 5.1\\bin "); P.standardinput.writeline ("mysqldump-h 192.168.0.1-p3306-uroot-p123456-q-d-r-e--skip-add-drop-table--default-character-set=utf8
--extended-insert=falseMysqlDBName> C + +Mysqldbnamenodata.sql " ); //- Q Fast Read,-D non-data,-r store stored procedures and functions,--extended-insert=false-line execution (needed when view is embedded),-e export event,--add-drop-tables Delete Table,-- skip-add-drop-table do not delete tablesP.standardinput.writeline ("Exit"); P.beginoutputreadline (); Strerror=p.StandardError.ReadToEnd (); p.WaitForExit (); if(!string. Isnullorwhitespace (strerror))//execution fails to jump out of {return ; } //Remove Definer (if the database is on a different server, it is likely to have permissions issues, replace the permissions section of the code)StreamReader sr =NewStreamReader (storedbnodatapath);Regex RG3 =NewRegex ("definer= '. {1,50} ' @ '% '"); //If the user name is longer, you can set it longer, but not too long, or replace the required data stringsql =Sr. ReadToEnd (); Sr. Close (); stringStroutput = Rg3. Replace (SQL,""); StreamWriter SW=NewStreamWriter (Storedbnodatapath,false, System.Text.Encoding.UTF8); Sw. Write (Stroutput); Sw. Close (); //In addition to data, table structure, views, stored procedures, functions, events are all importedP.start (); P.standardinput.writeline ("C:"); P.standardinput.writeline ("cd C:\\Program Files (x86) \\MySQL\\MySQL Server 5.1\\bin" );P.standardinput.writeline ("mysql-h 192.168.0.2-p3306-uroot-p123456 MysqlDBName<c \Mysqldbnamenodata.sql " ); P.standardinput.writeline ("Exit"); Strerror=p.StandardError.ReadToEnd (); p.WaitForExit (); if(!string. Isnullorwhitespace (strerror))//execution fails to jump out of {return ; }

Part II: Guide data. (To make importing data faster, don't add--extended-insert=false)

 //Export Data onlyP.start (); P.standardinput.writeline ("C:");  
P.standardinput.writeline ("cd C:\\Program Files (x86) \\MySQL\\MySQL Server 5.1\\bin ");P.standardinput.writeline ("mysqldump-h 192.168.0.1-p3306-uroot-p123456- q--no-create-info--default-character-set=utf8--skip-add-locks
mysqlDBName < c \mysqldbnameonlydata.sql "             );//- Q--no-create-info Export only data--skip-add-locks do not add table lockP.standardinput.writeline ("Exit"); Strerror=p.StandardError.ReadToEnd (); p.WaitForExit (); if(!string. Isnullorwhitespace (strerror)) {return ; } //Import DataP.start (); P.standardinput.writeline ("C:"); P.standardinput.writeline ("cd C:\\Program Files (x86) \\MySQL\\MySQL Server 5.1\\bin" );P.standardinput.writeline ("mysql-h 192.168.0.2-p3306-uroot-p123456 MysqlDBName<c \Mysqldbnameonlydata.sql " ); P.standardinput.writeline ("Exit"); Strerror=p.StandardError.ReadToEnd (); p.WaitForExit (); if(!string. Isnullorwhitespace (strerror)) {return ; } //Close ProcessP.close ();

MySQL Backup migration--mysqldump (. NET call Mysqldump.exe mode)--(Resolve view embedding ungrateful error)

Related Article

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.