背景:本次是机房异常断电,导致数据库文件损坏。在数据库自启动之后频繁宕机,在多次尝试以后,总结了一下几种方法,及供参考。
1.mariadb服务器断电重启之后Missing MLOG_CHECKPOINT的报错信息?
解决办法是,删除data目录下的ib_logfile0、ib_logfile1这两个文件,建议最好备份一份。
2.数据库文件损坏,导致频繁宕机
编辑 /etc/my.cnf,在[mysqld]小节添加如下两行:
innodb_force_recover = 3
innodb_purge_threads = 0
innodb_force_recovery=3 #mariadb数据库文件损坏重启,当参数值大于3的时候会对数据文件造成永久性的破坏。
1(SRV_FORCE_IGNORE_CORRUPT):忽略检查到的corrupt页。
2(SRV_FORCE_NO_BACKGROUND):阻止主线程的运行,如主线程需要执行full purge操作,会导致crash。
3(SRV_FORCE_NO_TRX_UNDO):不执行事务回滚操作。
4(SRV_FORCE_NO_IBUF_MERGE):不执行插入缓冲的合并操作。
5(SRV_FORCE_NO_UNDO_LOG_SCAN):不查看重做日志,InnoDB存储引擎会将未提交的事务视为已提交。
6(SRV_FORCE_NO_LOG_REDO):不执行前滚的操作。
3.启动命令设置强制回滚
/usr/sbin/mysqld --skip-grant-tables --general-log &
service mysql start --tc-heuristic-recover=ROLLBACK
[client] port = 3306 socket = /tmp/mysql.sock [mysqld] port = 3306 socket = /tmp/mysql.sock user = mariadb basedir = /usr/local/mariadb datadir = /data/mysql log_error = /data/mysql/mariadb.err pid-file = /data/mysql/mariadb.pid skip-external-locking key_buffer_size = 64M max_allowed_packet = 4M table_open_cache = 256 sort_buffer_size = 4M net_buffer_length = 18K read_buffer_size = 4M read_rnd_buffer_size =2M myisam_sort_buffer_size = 16M thread_cache_size = 32 query_cache_size = 32M tmp_table_size = 64M explicit_defaults_for_timestamp = true #skip-networking max_connections = 500 max_connect_errors = 100 open_files_limit = 65535 log-bin=mysql-bin binlog_format=mixed server-id = 1 expire_logs_days = 10 default_storage_engine = InnoDB innodb_file_per_table = 1 innodb_data_home_dir = /data/mysql innodb_data_file_path = ibdata1:10M:autoextend innodb_log_group_home_dir = /data/mysql innodb_buffer_pool_size = 256M innodb_log_file_size = 64M innodb_log_buffer_size = 8M innodb_flush_log_at_trx_commit = 10 innodb_lock_wait_timeout = 50 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash [myisamchk] key_buffer_size = 64M sort_buffer_size = 1M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout