Mysql 通过 Wireshark 检查查询过程

Mysql query process check via Wireshark

当客户端执行一个简单的 select 查询时,我试图了解后台发生了什么。

我正在使用 C# Asp.Net Webforms,并且我使用 WireShark 检查了进程。

public DBC(string procedureName, params object[] procParams)
{
    strError = null;
    using (MySqlConnection connection = new MySqlConnection(GetConnectionString()))
    {
        connection.Close();
        try
        {
            connection.Open();
            MySqlCommand cmd = new MySqlCommand(procedureName, connection);
            cmd.CommandType = CommandType.StoredProcedure;

            //if we use params for stored procedure
            if (procParams != null)
            {
                int i = 1;
                foreach (object paramValue in procParams)
                {
                    cmd.Parameters.Add(new MySqlParameter("@param_" + i, paramValue.ToString()));
                    i++;
                }
            }

            if (procedureName.Contains("get"))
            {
                dtLoaded = new DataTable();
                dtLoaded.Load(cmd.ExecuteReader());
            }
            else
            {
                cmd.ExecuteNonQuery();
            }
        }
        catch (Exception ex)
        {
            strError = ErrorHandler.ErrorToMessage(ex);
        }
        finally
        {
            connection.Close();
            connection.Dispose();
        }
    }
}

这是一个简单的 SELECT * FROM TABLE 查询,在 try-catch 语句中。在 finally 状态下,连接被关闭并被释放。

为什么会导致43进程?我不明白,为什么有这么多。有人可以解释我吗?

非常感谢!

我假设您使用的是 Oracle 的 Connector/NET。它在打开连接后执行许多非严格必要的查询,例如 SHOW VARIABLES 以检索一些服务器设置。 (在 8.0.17 及更高版本中,这有 been optimised slightly。)

执行存储过程需要检索有关存储过程的信息(以对齐参数);它比直接执行 SQL 语句更 "expensive"。 (您可以使用 CheckParameters=false 禁用它,但我不推荐它。)

您可以切换到 MySqlConnector if you want a more efficient .NET client library. It's been tuned for performance (in both client CPU time and network I/O) and won't perform as much unnecessary work when opening a connection and executing a query. (MySqlConnector is the client library used for the .NET/MySQL benchmarks in the TechEmpower Framework Benchmarks。)