断电后,linux中MySql服务无法启动

一、多次断电后,Linux数据库服务无法启动

(1).查看MySql服务启动日志

    查看MySQL的配置文件my.cnf:

     寻找my.cnf文件位置:

                 命令一:find / -name  my.cnf

                命令二:mysql --help|grep 'my.cnf'

输出

order of preference, my.cnf, $MYSQL_TCP_PORT,

/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf

/etc/my.cnf, /etc/mysql/my.cnf, /usr/local/etc/my.cnf, ~/.my.cnf 这些就是mysql默认会搜寻my.cnf的目录,顺序排前的优先。

my.cnf文件详情:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[client]
default-character-set=utf8
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
default-time-zone = '+8:00'
lower_case_table_names=1
max_connections = 1500
slow_query_log=TRUE                                       #开启慢日志
slow_query_log_file=/var/lib/mysql/localhost-slow.log     #慢日志存放位置
long_query_time=5
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log   #日志存放位置
pid-file=/var/run/mysqld/mysqld.pid
sql-mode=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

(2).MySql服务启动日志详情

日志部分内容:

2019-11-28T02:40:30.851051Z 0 [ERROR] InnoDB: Page [page id: space=1995, page number=333] log sequence number 175235920408 is in the future! Current system log sequence number 175147017572.
2019-11-28T02:40:30.851083Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery.
2019-11-28T02:40:30.851070Z 0 [Note] InnoDB: Page dump in ascii and hex (16384 bytes):
 len 16384; hex 5a2019-11-28T02:40:30.851128Z 0 [ERROR] InnoDB: Page [page id: space=1995, page number=1389] log sequence number 175244348496 is in the future! Current system log sequence number 175147017572.
ecd3932019-11-28T02:40:30.851186Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery.
000014e5000014e2000014e000000028cdac455345bf0000002019-11-28T02:40:30.851286Z 0 [ERROR] InnoDB: Page [page id: space=1995, page number=1407] log sequence number 175246038284 is in the future! Current system log sequence number 175147017572.
2019-11-28T02:40:30.851301Z 0 [ERROR] InnoDB: Page [page id: space=1995, page number=1281] log sequence number 175243719473 is in the future! Current system log sequence number 175147017572.

(3).MySql服务启动日志分析

日志说明的是InnoDB出现问题,这样需要做的操作如下

(4).数据库恢复

   1).配置my.cnf

     修改my.cnf文件,在my.cnf中的[mysqld]中添加:

    nnodb_force_recovery = 6

解释:
innodb_force_recovery可以设置为1-6,大的数字包含前面所有数字的影响。
具体数字对应的含义:
1-----(SRVFORCEIGNORECORRUPT):忽略检查到的corrupt页。
2-----(SRVFORCENOBACKGROUND):阻止主线程的运行,如主线程需要执行full purge操作,会导致crash。
3-----(SRVFORCENOTRXUNDO):不执行事务回滚操作。
4-----(SRVFORCENOIBUFMERGE):不执行插入缓冲的合并操作。
5-----(SRVFORCENOUNDOLOGSCAN):不查看重做日志,InnoDB存储引擎会将未提交的事务视为已提交。
6-----(SRVFORCENOLOG_REDO):不执行前滚的操作。

2).原有数据备份

       a).启动MySql服务,利用客户端navicat备份原有数据库

         命令一:systemctl  start mysqld

       b).删除原有数据库

3)删除ib_logfile0、ib_logfile1、ibdata1

备份MySQL数据目录下的ib_logfile0、ib_logfile1、ibdata1三个文件,然后将这三个文件删除

  命令一:查找文件 find / -name ib_logfile0

4)将my.cnf中

innodb_force_recovery = 1或2——6几个数字这行配置删除或者配置为innodb_force_recovery = 0,重启MySQL服务

5) 新建数据库,将备份的数据导入

 

附参考资料:

资料一:https://blog.csdn.net/l1028386804/article/details/77199194

资料二:https://blog.51cto.com/net881004/2060132

资料三:https://www.cnblogs.com/studywithallofyou/p/11357393.html

 

 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值