服务器并发truncate命令崩溃后,MySQL INNODB损坏


9

我认为我的服务器今天崩溃了,原因是我们的一个INNODB表上有一个并发的truncate table命令。服务器可以重新启动,但是在启动之后,每次我尝试发出SQL命令时,都会出现以下错误:

ERROR 2006 (HY000): MySQL server has gone away

这是在日志中发生的事情:

121206 01:11:12  mysqld restarted
121206  1:11:13  InnoDB: Started; log sequence number 275 559321759
InnoDB: !!! innodb_force_recovery is set to 1 !!!
121206  1:11:13 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.0.95-log'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Source distribution
InnoDB: Error: trying to load index PRIMARY for table 
InnoDB: but the index tree has been freed!
121206  1:11:37 - mysqld got signal 11 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help diagnose
the problem, but since we have already crashed, something is definitely wrong
and this may fail.

key_buffer_size=134217728
read_buffer_size=1048576
max_used_connections=1
max_connections=400
threads_connected=1
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_connections = 950272 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd=0x9900950
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
Cannot determine thread, fp=0x46353fa0, backtrace may not be correct.
Stack range sanity check OK, backtrace follows:
(nil)
New value of fp=0x9900950 failed sanity check, terminating stack trace!
Please read http://dev.mysql.com/doc/mysql/en/using-stack-trace.html and follow instructions on how to resolve the stack trace. Resolved
stack trace is much more helpful in diagnosing the problem, so please do
resolve it
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort...
thd->query at 0x993e500 =
thd->thread_id=1
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.

我已经在网上搜索过,但提示它是一个MySQL错误,但我不知道如何解决。我正在使用MySQL 5.0.95版。

似乎必须创建一个新数据库并将旧数据转储到新数据库中,但是如果我什至不能向当前数据库发出任何SQL命令,该怎么办?

---更新---
版本:'5.0.95-log'套接字:'/var/lib/mysql/mysql.sock'端口:3306源分发InnoDB:错误:试图为表InnoDB加载索引PRIMARY:索引树已释放!121206 4:13:41-mysqld收到信号11; 这可能是因为您遇到了错误。此二进制文件或与之链接的库之一也可能已损坏,构建不正确或配置错误。硬件故障也可能导致此错误。我们将尽力收集一些信息,希望可以帮助诊断问题,但是由于我们已经崩溃,所以肯定有问题,并且可能会失败。

key_buffer_size=134217728
read_buffer_size=1048576
max_used_connections=1
max_connections=400
threads_connected=1
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_connections = 950272 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd=0x17fb8950
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
Cannot determine thread, fp=0x464a3fa0, backtrace may not be correct.
Stack range sanity check OK, backtrace follows:
(nil)
New value of fp=0x17fb8950 failed sanity check, terminating stack trace!
Please read http://dev.mysql.com/doc/mysql/en/using-stack-trace.html and follow instructions on how to resolve the stack trace. Resolved
stack trace is much more helpful in diagnosing the problem, so please do
resolve it
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort...
thd->query at 0x17ff6500 =
thd->thread_id=3
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.

Number of processes running now: 0
121206 04:13:41  mysqld restarted
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
121206  4:13:42  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
121206  4:13:43  InnoDB: Started; log sequence number 275 559323148
121206  4:13:43 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.0.95-log'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Source distribution

Answers:


6

方面#1

引起我注意的第一件事是这条线

InnoDB:错误:试图为表/加载索引PRIMARY

这表明您有一个使用InnoDB存储引擎的表

InnoDB有趣的是,PRIMARY KEY的存储方式。它存储在称为gen_clust_index的结构中,或更常见的称为聚簇索引。

我的直接猜测是某个PRIMARY KEY条目太大

请考虑一些有关使用长PRIMARY KEY的优缺点的文章:

然后查看是否<DB Hidden>.<Table Hidden>需要重新设计。

方面#2

根据您对并行截断表的猜想,这听起来很危险。为什么?InnoDB的执行TRUNCATE TABLE的DDLDML。我以前写过有关此的内容:

方面#3

一些调整建议

请添加以下内容到 my.ini

[mysqld]
max_allowed_packet=1G
innodb_fast_shutdown=0

启动mysql

在另一个会话中,运行tail -f <errorlogfile>并观看InnoDB Crash Recovery。

如果mysql已完全启动,并且InnoDB崩溃恢复已完成,请尝试立即关闭mysql。您可能需要调整InnoDB事务日志的大小。

对不起这些建议,但我在这里瞎了。

请在问题中发布以下内容:

  • 你整个 my.cnf
  • 板载多少内存

更新美国东部时间2012-12-05 12:09

请执行以下操作:

步骤01)将这些更改添加到 my.cnf

[mysqld]
max_allowed_packet=1G
innodb_fast_shutdown=0
innodb_thread_concurrency=0

步骤02) service mysql restart

确保mysql启动

步骤03)您需要调整ib_logfile0和ib_logfile1的大小(24M可能太小)

service mysql stop
cd /var/lib/mysql
mv ib_logfile0 ib_logfile0.bak
mv ib_logfile1 ib_logfile1.bak

步骤04)将这些更改添加到 my.cnf

[mysqld]
innodb_log_file_size=512M
innodb_log_buffer_size=8M

步骤05) service mysql start

mysqld将分别重新创建ib_logfile0和ib_logfile1 512M

现在,尝试看看会发生什么...。

更新2012-12-05 12:18 EDT

同时,请阅读我在mysql数据包上的ServerFault帖子及其对innodb_log_file_sizeinnodb_log_buffer_size的大小含义,这是我从其他人的ServerFault帖子中学到

更新2012-12-05 14:28 EDT

我出于这个问题编辑了对客户表的所有引用。

根本原因是损坏的页面ibdata1内部混有数据和索引页面。我帮助Andrew移出了数据,使用innodb_file_per_table重新创建了ibdata1 ,然后Andrew重新加载了数据。


感谢您的评论Rolando。我一定会重新考虑主键的结构。同时,我将浏览您的文章,看看是否可以使我们的服务器备份并尽快运行。
安德鲁

ibdata1的某些部分的页面已损坏。我与托管客户多次见过这种情况。
RolandoMySQLDBA


根据要求,我清除了所有评论以隐藏敏感信息。
RolandoMySQLDBA

@RolandoMySQLDBA,能否请您详细说明一下您是如何发现根本原因的,我是说您是如何找到答案的?您采取了哪些步骤来解决此问题?
巴普什裤
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.