日期:2014-05-16  浏览次数:21280 次

50分,MySQL查询异常:Fatal error encountered during command execution。
在使用存储过程查询时,出现错误提示:Fatal error encountered during command execution,每次发现查询时间较长时(超出40秒),出现的几率很大,但存储过程本身没什么问题,因为,同样条件,当查询数据较少时也不会出问题。
MySql版本:5.0.27
查询数据表记录大概有200万条,分页得出查询记录后,还要再关联(Join)两个表。

------解决方案--------------------
代码贴出来看看,在连接字段上建立索引没有
------解决方案--------------------
数据量好大,关注...
------解决方案--------------------
内存不足?
------解决方案--------------------
Description:
ExecuteReader() method of the MySqlCommand object displays "Fatal error encountered during
command execution" message when the simple statement below is executed.

select @data := 3, @data * 4;

How to repeat:
MySqlConnection con = new MySqlConnection();
con.ConnectionString = "Database=sampledb;Data Source=localhost;User Id=root;Password=a";
con.Open();
// Connection ok
string cmdText = "select @data := 3, @data * 4;";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
MySqlDataReader r = cmd.ExecuteReader();
r.Read();
MessageBox.Show(r.GetInt32(1).ToString());
r.Close();
con.Close();
r.Dispose();
con.Dispose();[17 Nov 2008 17:26] Reggie Burnett 
Neoh

This is not a bug. You are attempting to use user variables in your sql. The default
mode for Connector/Net assumes you will not be using user variables (as most users don't)
and so it sees @data and expects to find a parameter named @data. When it doesn't find
one it throws an exception.

To fix this add 'allow user variables=true' to your connection string. In this mode it
will not complain when it sees @data but doesn't find a parameter of that name.


你的存储过程是否使用了自定义变量?不过你说查询数据量少的时候不出问题,似乎和这个自定义变量又无关。
------解决方案--------------------
1 我觉得是由于慢查询导致存储过程出现问题的。
2 在存储过程中增加一些异常机制处理,将出错的内容记录下来。
3 检查 MySQL 慢查询日志 和 Error 日志,看看是否有记录相关内容。
------解决方案--------------------
关注下,呵呵。LZ给的细节过少了。