gpt4 book ai didi

c# - Mysql 备份超时过期 - C#

转载 作者:搜寻专家 更新时间:2023-10-30 20:25:05 24 4
gpt4 key购买 nike

我构建了一个应用程序来从服务器备份我的 MYSQL 数据库,一天一天,数据库变得比以前更大,有时会触发错误(从我的角度来看):

Message: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Full: MySql.Data.MySqlClient.MySqlException (0x80004005): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.TimeoutException: Timeout in IO operation at MySql.Data.MySqlClient.TimedStream.StopTimer() at MySql.Data.MySqlClient.TimedStream.Read(Byte[] buffer, Int32 offset, Int32 count) at System.IO.BufferedStream.Read(Byte[] array, Int32 offset, Int32 count) at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count) at MySql.Data.MySqlClient.MySqlStream.LoadPacket() at MySql.Data.MySqlClient.MySqlStream.ReadPacket() at MySql.Data.MySqlClient.NativeDriver.FetchDataRow(Int32 statementId, Int32 columns) at MySql.Data.MySqlClient.Driver.FetchDataRow(Int32 statementId, Int32 columns) at MySql.Data.MySqlClient.ResultSet.GetNextRow() at MySql.Data.MySqlClient.ResultSet.NextRow(CommandBehavior behavior) at MySql.Data.MySqlClient.MySqlDataReader.Read() at MySql.Data.MySqlClient.ExceptionInterceptor.Throw(Exception exception) at MySql.Data.MySqlClient.MySqlConnection.Throw(Exception ex) at MySql.Data.MySqlClient.MySqlConnection.HandleTimeoutOrThreadAbort(Exception ex) at MySql.Data.MySqlClient.MySqlDataReader.Read() at MySql.Data.MySqlClient.MySqlBackup.Export_RowsData(String tableName, String selectSQL) at MySql.Data.MySqlClient.MySqlBackup.Export_Rows(String tableName, String selectSQL) at MySql.Data.MySqlClient.MySqlBackup.Export_TableRows() at MySql.Data.MySqlClient.MySqlBackup.ExportStart() at MySql.Data.MySqlClient.MySqlBackup.ExportToFile(String filePath) at MYSQL_Auto_Backup.Form1.Backup() in c:\Users\Belal\Documents\Visual Studio 2012\Projects\MYSQL Auto Backup\MYSQL Auto Backup\Form1.cs:line 132

代码:

// Backup...
DateTime Time = DateTime.Now;
year = Time.Year;
month = Time.Month;
day = Time.Day;
hour = Time.Hour;
minute = Time.Minute;
second = Time.Second;
millisecond = Time.Millisecond;

//Save file to Path with the current date as a filename
string path;
path = txb_Path.Text + year + "-" + month + "-" + day + "--" + hour + "-" + minute + "-" + second + ".sql";
file = path;
using (MySqlConnection conn = new MySqlConnection(connectionString))
{
using (MySqlCommand cmd = new MySqlCommand())
{
using (MySqlBackup mb = new MySqlBackup(cmd))
{
cmd.Connection = conn;
conn.Open();
mb.ExportToFile(file);
conn.Close();
}
}
}

最佳答案

您可以使用“CommandTimeout”属性更改超时。

您可能还需要考虑许多其他的备份方式(例如通过数据库的管理工具)。例如,请参见以下内容:
https://dev.mysql.com/doc/mysql-enterprise-backup/3.11/en/meb-scheduled-backups.html

另一个小问题。对于以下行:

string path;
path = txb_Path.Text + year + "-" + month + "-" + day + "--" + hour + "-" + minute + "-" + second + ".sql";
file = path;

为什么不做类似的事情

file = String.Format("{0}{1}-{2}-3--{4}-{5}...", txb_Path.Text, year, month...);

您正在执行的字符串连接实际上在 .NET 中相当昂贵,因为 .NET 字符串是不可变的。

关于c# - Mysql 备份超时过期 - C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38753635/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com