Public static void BackupOrRestoreDB (string HostName, string PWD, string DbName, string filename)
{
The Process of p=new Process ();
P. tartInfo. FileName="CMD. Exe";
P. tartInfo. UseShellExecute=false;
P. tartInfo. RedirectStandardInput=true;
P. tartInfo. RedirectStandardOutput=true;
P. tartInfo. RedirectStandardError=true;
P. tartInfo. CreateNoWindow=true;
//bin directory specified MySql program
p. tartInfo. WorkingDirectory=GetMysqlPath () + "\ \ bin";
P. tart ();
/* * * * * * * * * * * * *
* the backup command
* * * * * * * * * * * * * */
//simple format
//string strSql="mysqldump - quick - host=192.168.0.52 -u root - pdstest2011 dsrsksdb_v6 & gt; D: \ \ test_20151227110010. SQL ";
If (Directory. The Exists (AppSetting. GetConfig (" AppSetting: DBBakpath "))==false)
{
Directory. CreateDirectory (AppSetting. GetConfig (" AppSetting: DBBakpath "));
}
String strSql="mysqldump - quick - host=" + HostName + "-u root -p" + + "" + DbName +" PWD & gt; "+ AppSetting. GetConfig (" AppSetting: DBBakpath") + filename + ". The SQL ";
P. tandardInput. WriteLine (strSql + "& amp; The exit ");
P. tandardInput. AutoFlush=true;
//display mode 2
The string result=p. tandardOutput. ReadToEnd ();
Console. WriteLine (result);
//return Warning results - Warning: Using a password on the command line interface can be insecure.
String result2=p. tandardError. ReadToEnd ();
Console. WriteLine (result2);
//display mode 3
ShowValue (p);
P.W aitForExit ();
P.C lose ();
}
Public static string GetMysqlPath ()
{
String strPath=string. The Empty;
String STRSQL="select @ @ basedir as basePath from dual";
The DataSet dsLJ=DbHelperMySQL. Query (STRSQL);
if (! DsLJ. DsIsNullOrEmpty ())
{
StrPath=dsLJ. Tables [0]. Rows [0] [r]. "basePath" ToString ();
}
StrPath=strPath. Replace ("/", "\ ");
Return strPath;
}
When the database in the phone when I use this way to be successful backup, when the database on the company server for backup will prompt "directory name is invalid, I change how to solve?