information_schema 查询期间 MySQL 致命错误(软件导致连接中止)

Posted

技术标签:

【中文标题】information_schema 查询期间 MySQL 致命错误(软件导致连接中止)【英文标题】:MySQL fatal error during information_schema query (software caused connection abort) 【发布时间】:2014-08-30 06:02:21 【问题描述】:

我通过其 .NET 连接器 (6.8.3) 广泛使用 mysql 服务器 (5.6) 数据库。出于性能原因,所有表都是使用 MyISAM 引擎创建的。我只有一个进程,一个线程顺序访问数据库,所以不需要事务和并发。

请注意这不太可能是超时配置问题,因为我的查询很简单。我确实阅读了所有与超时相关的问题(下面的链接)。当然,我可能是错的,但只是说“增加 net_write_timeout 参数”而不解释为什么它在这里可能是相关的,这不是一个答案。

我的一些表是在程序执行期间动态创建的,所以我使用 create on first use 习惯用法,使用以下方法检查表是否存在:

private bool TableExists(Space baseSpace, Space extendedSpace)

    var tableName = GenerateTableName(baseSpace, extendedSpace);

    var sqlConnection = this.connectionPool.Take();

    this.existsCommand.Connection = sqlConnection;
    this.existsCommand.Parameters["@tableName"].Value = tableName.Trim('`');

    var result = existsCommand.ExecuteScalar() as long?;

    this.connectionPool.Putback(sqlConnection);

    return result == 1;

existsCommand里​​面的查询如下(为了便于阅读,这里分成两行):

SELECT COUNT(*) FROM information_schema.tables 
WHERE table_schema = 'my_schema' AND table_name = @tableName

this.existsCommand.Parameters["@tableName"].Value 变量的值包含表的正确名称,在这种情况下已经存在 ("sample_matches_A_to_A_x")。

this.connectionPool.Take() 方法从我的可用连接集合中返回满足以下谓词的第一个 MySqlConnection 对象:

private bool IsAvailable(MySqlConnection connection)

    return connection != null
        && connection.State == System.Data.ConnectionState.Open;

通常这可以正常工作几个小时,然后突然在该行发生异常:

var result = existsCommand.ExecuteScalar() as long?;

内容如下:

命令执行过程中遇到致命错误

堆栈跟踪:

在 MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior 行为)

在 MySql.Data.MySqlClient.MySqlCommand.ExecuteScalar()

在 implementation.SampleMatchesMySqlTable.TableExists(Space baseSpace, Space extendedSpace) in C:...\SampleMatchesMySqlTable.cs:line 168

内部异常:

无法将数据写入传输连接:软件导致连接中止。

内部异常:

软件导致连接中止。

ErrorCode 等于 10053 且 SocketErrorCode 为 System.Net.Sockets.SocketError.ConnectionAborted

最里面异常的堆栈跟踪:

在 System.Net.Sockets.Socket.Send(Byte[] 缓冲区,Int32 偏移量,Int32 大小,SocketFlags socketFlags)

在 System.Net.Sockets.NetworkStream.Write(Byte[] 缓冲区,Int32 偏移量,Int32 大小)


我查看了以下可能的重复项,不幸的是,它们似乎与此处无关,除了一个:

SHOW TABLES encountered Fatal error encountered during command execution

很遗憾,它没有提供足够的信息来确定它是否是完全重复的,也没有得到回答。


有涉及到超时问题。我的查询很小,只返回一个整数,并在包含类似 20 个其他表的元表中搜索一个表。

Fatal error encountered during command execution. in C# when i use Insert Into

https://***.com/questions/7895178/fatal-error-in-mysql

MySQL Exception - Fatal Error Encountered During Data Read

Fatal error encountered during data read

Fatal error causing timeout -mysql

ADO.Net Entity framework, Fatal error encountered during data read


关于读取结果集的不同错误:

Fatal error encountered during command execution


语法错误和连接字符串问题:

Mysql Fatal error encountered during command execution

fatal error encountered during execution... during update

Fatal error encountered during command execution

fatal error encountered during command execution during update

fatal error encountered during command execution c# mysql

Fatal error encountered during command execution with a mySQL INSERT

I have Fatal error encountered during command execution

MySql exception was unhandled - Fatal error encountered during command execution

https://***.com/questions/24098561/mysql-fatal-error-encountered-during-command-execution-in-c-sharp

Fatal Error Encounter During Command Execution MySQL VB

"Fatal error encountered during command execution." mysql-connector .net

"Fatal error encountered during command execution."

C#, MySQL - fatal error encountered during command execution- Checked other solutions, something I am Missing

创建视图: "fatal error encountered during command execution" when trying to add a view from MySQL DB


读取 CSV 文件:

Fatal error encountered during command execution while importing from csv to mysql

MySQL fatal error encountered during command execution - looping through all csv files in folder for load data local infile

【问题讨论】:

【参考方案1】:

我最终将IsAvailable 方法修改如下:

private bool IsAvailable(MySqlConnection connection)

    var result = false;

    try
    
        if (connection != null)
        
            result = connection.Ping();
        
    
    catch (Exception e)
    
        Console.WriteLine("Ping exception: " + e.Message);
    

    return result && connection.State == System.Data.ConnectionState.Open;

.Ping 调用在验证连接状态方面似乎比它的属性更好,尽管它的文档记录很差。同时从我读过的其他一些来源:

另一种方法是运行像SELECT 1 FROM DUAL 这样的简单查询,而不是调用Ping


此外,似乎有时DataReader,即使它已被释放(一切都通过using 语句实现),仍会在一段时间内附加到连接。因此,我将条件修改为:

if (connection != null && connection.State == ConnectionState.Open)

只要附加了DataReaderState 属性就具有Executing 值,因此另外验证开头是否为Open 在这里可以正常工作。

【讨论】:

以上是关于information_schema 查询期间 MySQL 致命错误(软件导致连接中止)的主要内容,如果未能解决你的问题,请参考以下文章

可以对 information_schema 崩溃表进行 mysql 查询吗?

INFORMATION_SCHEMA.COLUMNS 突然为空

查询INFORMATION_SCHEMA表很慢的性能优化

从数据流中查询 BigQuery 的 INFORMATION_SCHEMA.TABLES 会导致错误

我们如何识别在 bigquery information_schema 中使用 Tableau 运行的大查询查询

当 INFORMATION_SCHEMA 拒绝访问时如何查询表的列?