前言

mysql服务运行一段时间后,会出现innoDB宕掉的情况

排查处理
日志错误信息

docker logs -f mysql

... ... 
InnoDB: Database page corruption on disk or a failed
InnoDB: file read of page 5.
InnoDB: You may have to recover from a backup.
2020-05-27 22:02:11 7f2d1c7b9040 InnoDB: Page dump in ascii and hex (16384 bytes):
 len 16384; hex c98 ... ...
 ,,, ,,,
  • 同时也会存在的相关日志信息
... ...
InnoDB: Page may be a transaction system page
InnoDB: Database page corruption on disk or a failed
InnoDB: file read of page 5.
InnoDB: You may have to recover from a backup.
InnoDB: It is also possible that your operating
InnoDB: system has corrupted its own file cache
InnoDB: and rebooting your computer removes the
InnoDB: error.
InnoDB: If the corrupt page is an index page
InnoDB: you can also try to fix the corruption
InnoDB: by dumping, dropping, and reimporting
InnoDB: the corrupt table. You can use CHECK
InnoDB: TABLE to scan your table for corruption.
InnoDB: See also http://dev.mysql.com/doc/refman/5.6/en/forcing-innodb-recovery.html
InnoDB: about forcing recovery.
InnoDB: Ending processing because of a corrupt database page.
2020-06-18 11:40:41 7fb8f8789040  InnoDB: Assertion failure in thread 140432419360832 in file buf0buf.cc line 4295
InnoDB: We intentionally generate a memory trap.
InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.6/en/forcing-innodb-recovery.html
InnoDB: about forcing recovery.
03:40:41 UTC - mysqld got signal 6 ;
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=8388608
read_buffer_size=131072
max_used_connections=0
max_threads=151
thread_count=0
connection_count=0
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 68109 K  bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

Thread pointer: 0x0
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...
stack_bottom = 0 thread_stack 0x40000
mysqld(my_print_stacktrace+0x2c)[0x7fb8f8e5688c]
mysqld(handle_fatal_signal+0x4b1)[0x7fb8f8bf3ea1]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x110e0)[0x7fb8f83620e0]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0xcf)[0x7fb8f6efefff]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x16a)[0x7fb8f6f0042a]
mysqld(+0x8076b9)[0x7fb8f8f9b6b9]
mysqld(+0x81aad3)[0x7fb8f8faead3]
mysqld(+0x81b53c)[0x7fb8f8faf53c]
mysqld(+0x8025f9)[0x7fb8f8f965f9]
mysqld(+0x7c1234)[0x7fb8f8f55234]
mysqld(+0x7acf6f)[0x7fb8f8f40f6f]
mysqld(+0x6f0ea8)[0x7fb8f8e84ea8]
mysqld(_Z24ha_initialize_handlertonP13st_plugin_int+0x46)[0x7fb8f8b41a16]
mysqld(+0x4e34c1)[0x7fb8f8c774c1]
mysqld(_Z11plugin_initPiPPci+0x754)[0x7fb8f8c7d654]
mysqld(+0x3a5cab)[0x7fb8f8b39cab]
mysqld(_Z11mysqld_mainiPPc+0x41b)[0x7fb8f8b3ac3b]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf1)[0x7fb8f6eec2e1]
mysqld(_start+0x2a)[0x7fb8f8b2eafa]
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的docker-compose.yml文件
version: "3.5"
services:
  mysql:
    image: mysql:5.6
    container_name: mysql5.6
    hostname: mysql5.6
    ports:
      - 3309:3306    
    environment:
      - MYSQL_DATABASE=nature
      - MYSQL_USER=nature
      - MYSQL_PASSWORD=root@1234
      - MYSQL_ROOT_PASSWORD=nature@1234
      - SET_CONTAINER_TIMEZONE=true
      - CONTAINER_TIMEZONE=Asia/Shanghai
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /opt/test/mysql:/var/lib/mysql:Z
    command: ["--character-set-server=utf8mb4","--collation-server=utf8mb4_unicode_ci","--lower-case-table-names=1"]
    restart: always
    tty: true
  • 启动部署
    docker-compose up -d
mysql配置增加参数innodb_force_recovery=1
  • 停止mysql服务
    docker-compose down

修正docker-compose.yml文件,如下所示:

version: "3.5"
services:
  mysql:
    image: mysql:5.6
    container_name: mysql5.6
    hostname: mysql5.6
    ports:
      - 3309:3306    
    environment:
      - MYSQL_DATABASE=nature
      - MYSQL_USER=nature
      - MYSQL_PASSWORD=root@1234
      - MYSQL_ROOT_PASSWORD=nature@1234
      - SET_CONTAINER_TIMEZONE=true
      - CONTAINER_TIMEZONE=Asia/Shanghai
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /opt/test/mysql:/var/lib/mysql:Z
    command: ["--character-set-server=utf8mb4","--collation-server=utf8mb4_unicode_ci","--lower-case-table-names=1","--innodb_force_recovery=1"]
    restart: always
    tty: true
  • 启动mysql服务
    docker-compose up -d
备份及恢复数据库
  • 备份数据库
    docker exec -it mysql5.6 mysqldump -uroot -proot@1234 xxx[数据库名] > xxx.sql

  • 还原数据库
    docker exec -it mysql5.6 mysql -uroot -proot@1234 xxx[数据库名] < xxx.sql

还原mysql初始配置
version: "3.5"
services:
  mysql:
    image: mysql:5.6
    container_name: mysql5.6
    hostname: mysql5.6
    ports:
      - 3309:3306    
    environment:
      - MYSQL_DATABASE=nature
      - MYSQL_USER=nature
      - MYSQL_PASSWORD=root@1234
      - MYSQL_ROOT_PASSWORD=nature@1234
      - SET_CONTAINER_TIMEZONE=true
      - CONTAINER_TIMEZONE=Asia/Shanghai
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /opt/test/mysql:/var/lib/mysql:Z
    command: ["--character-set-server=utf8mb4","--collation-server=utf8mb4_unicode_ci","--lower-case-table-names=1"]
    restart: always
    tty: true
  • 启动部署
    docker-compose up -d
结语

仅供参考

Logo

云原生社区为您提供最前沿的新闻资讯和知识内容

更多推荐