MySQL INNODB เกิดความเสียหายหลังจากเซิร์ฟเวอร์ขัดข้องระหว่างคำสั่ง truncate


9

เซิร์ฟเวอร์ของฉันทำงานล้มเหลววันนี้ฉันคิดว่าเนื่องจากคำสั่งตัดทอนตารางพร้อมกันบนหนึ่งในตาราง INNODB ของเรา เซิร์ฟเวอร์สามารถเริ่มต้นใหม่ได้ แต่หลังจากเริ่มทำงานทุกครั้งที่ฉันพยายามออกคำสั่ง 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- บันทึก': '/ var/lib/mysql/mysql.sock' พอร์ต: 3306 การกระจายแหล่งที่มา InnoDB: ข้อผิดพลาด: พยายามโหลดดัชนีหลักสำหรับตาราง InnoDB: แต่ ต้นไม้ดัชนีได้รับการปลดปล่อย! 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

คำตอบ:


6

ASPECT # 1

สิ่งแรกที่ดึงดูดสายตาฉันคือเส้นนี้

InnoDB: ข้อผิดพลาด: พยายามโหลดดัชนีหลักสำหรับตาราง /

สิ่งนี้บ่งชี้ว่าคุณมีตารางโดยใช้ InnoDB Storage Engine

สิ่งที่น่าสนใจเกี่ยวกับ InnoDB คือวิธีการจัดเก็บคีย์หลัก มันถูกเก็บไว้ในโครงสร้างที่เรียกว่าgen_clust_indexหรือที่รู้จักกันทั่วไปว่าเป็นดัชนีแบบคลัสเตอร์

ฉันเดาได้ทันทีว่ารายการคีย์หลักบางรายการใหญ่เกินไป

โปรดพิจารณาบทความเกี่ยวกับข้อดีข้อเสียและความน่าเกลียดของการใช้คีย์หลักแบบยาว:

จากนั้นดูว่า<DB Hidden>.<Table Hidden>จำเป็นต้องได้รับการออกแบบใหม่หรือไม่

ASPECT # 2

ในแง่ของการคาดเดาของคุณเกี่ยวกับตารางการตัดทอนแบบขนานนั่นฟังดูอันตราย ทำไม? InnoDB ทำการตัดตารางเป็นไม่ได้DDL DMLฉันได้เขียนเกี่ยวกับเรื่องนี้มาก่อน:

ASPECT # 3

คำแนะนำการปรับแต่งบางอย่าง

โปรดเพิ่มรายการต่อไปนี้ลงใน my.ini

[mysqld]
max_allowed_packet=1G
innodb_fast_shutdown=0

เริ่ม mysql

ในเซสชันอื่นให้เรียกใช้tail -f <errorlogfile>และดูการกู้คืนความเสียหายของ InnoDB

หาก mysql เริ่มต้นการสำรองข้อมูลอย่างสมบูรณ์และการกู้คืนความเสียหายของ InnoDB เสร็จสมบูรณ์แล้วให้ลองปิด mysql ทันที คุณอาจต้องปรับขนาดบันทึกการทำธุรกรรม InnoDB ของคุณ

ขออภัยสำหรับคำแนะนำเสริมเหล่านี้ แต่ฉันกำลังบินตาบอดที่นี่

กรุณาโพสต์ต่อไปนี้ในคำถาม:

  • ของคุณทั้งหมด my.cnf
  • จำนวนแรมบนเครื่อง

อัพเดท 2012-12-05 12:09 EDT

กรุณาทำดังต่อไปนี้:

ขั้นตอนที่ 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

ในระหว่างนี้โปรดอ่านโพสต์ ServerFault ของฉันในแพ็คเก็ตของ MySQLและความหมายการปรับขนาดของมันเกี่ยวกับการที่มีinnodb_log_file_sizeและinnodb_log_buffer_sizeตามที่ผมได้เรียนรู้จากการโพสต์ ServerFault ของคนอื่น

อัพเดท 2012-12-05 14:28 EDT

ฉันแก้ไขการอ้างอิงทั้งหมดไปยังตารางลูกค้าจากคำถามนี้

สาเหตุที่แท้จริงคือหน้าที่เสียหายในหน้าibdata1ข้อมูลและหน้าผสมภายใน ฉันช่วยให้แอนดรูว์ย้ายข้อมูลออกสร้าง ibdata1 ใหม่ด้วยinnodb_file_per_tableและแอนดรูโหลดข้อมูลอีกครั้ง


ขอบคุณสำหรับความคิดเห็นของคุณ Rolando ฉันจะพิจารณาโครงสร้างของคีย์หลักอย่างแน่นอน ในขณะเดียวกันฉันจะผ่านบทความของคุณและดูว่าฉันสามารถรับเซิร์ฟเวอร์ของเราสำรองและเรียกใช้โดยเร็ว
แอนดรู

บางส่วนของ ibdata1 มีหน้าเสียหาย ฉันเคยเห็นเงื่อนไขนี้หลายครั้งกับลูกค้าที่โฮสต์ของฉัน
RolandoMySQLDBA


ตามที่ร้องขอฉันจะลบความคิดเห็นทั้งหมดเพื่อซ่อนข้อมูลที่ละเอียดอ่อน
RolandoMySQLDBA

@RolandoMySQLDBA คุณช่วยอธิบายได้อย่างละเอียดว่าคุณตรวจพบสาเหตุที่แท้จริงได้อย่างไรฉันหมายความว่าคุณเข้าใจสิ่งนี้ได้อย่างไร และคุณทำตามขั้นตอนอะไรเพื่อแก้ไขปัญหานี้?
Bhupesh Pant
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.