背景
突然断电或者其他异常情况导致,mysql 索引或者binlog文件损坏,无法启动怎么办?本文将介绍Mysql数据重置方法
修改配置
vim /etc/my.cnf
innodb_force_recovery=3
systemctl restart mysql
备份
mysqldump -u root -p --all-databases > backup_all_${日期}.sql
systemctl stop mysql
数据初始化
rm -rf /data/mysql/data/*
/usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/my.cnf \
--basedir=/usr/local/mysql/ \
--datadir=/data/mysql/data/ \
--user=mysql \
--initialize-insecure \
--ssl \
--explicit_defaults_for_timestamp \
--verbose
修改配置
vim /etc/my.cnf
innodb_force_recovery=0
systemctl restart mysql
账号初始化
# 第一次登录密码为空
mysql -uroot -p
Enter password:
alter user 'root'@'localhost' identified by '${密码}';
grant all on *.* to 'root'@'%'IDENTIFIED BY '${密码}';
flush privileges;
恢复
nohup mysql -uroot -pgzgd < /data/mysql/backup_all_20220519.sql >/data/mysql/nohup.log 2>&1 &