wdcp面板和宝塔面板环境mysql数据库innodb损坏异常重建脚本,以下脚本中的路径根据实际情况进行替换调整。
WDCP面板环境
#!/bin/bash dbuser='root' dbpass='vfkahp2p' mysqldata='/home/wddata/var' mycnf='/www/wdlinux/etc/my.cnf' mysql_e='/www/wdlinux/mysql/bin/mysql' mysqldump_e='/www/wdlinux/mysql/bin/mysqldump' mysqlbakpath="/home/bkmysql/$(date +%Y%m%d%H%M%S)" function stop_mysql(){ service mysqld stop if [ $? -ne 0 ];then ps -e|grep mysql|awk '{print $1}'|xargs kill -9 fi } mkdir -p $mysqlbakpath sed -i -e '/\[mysqld\]/a innodb_force_recovery=3' $mycnf stop_mysql service mysqld start #start dump innodb mysql if [ $? -eq 0 ];then cd $mysqldata ls *\/*.ibd -h|awk -F'/' '{print $1}'|uniq|grep -v 'mysql' > $mysqlbakpath/1.txt for i in `cat $mysqlbakpath/1.txt` do echo "dump $i" $mysqldump_e -f -u$dbuser -p$dbpass $i > $mysqlbakpath/$i.sql done fi #end dump innodb mysql #start bkup innodb mysql cd $mysqldata stop_mysql mv -f ibdata1 ib_logfile0 ib_logfile1 $mysqlbakpath for i in `cat $mysqlbakpath/1.txt` do mv -f $i $mysqlbakpath done #end bkup innodb mysql sed -i -e '/innodb_force_recovery=3/d' $mycnf service mysqld start #start Import mysql if [ $? -eq 0 ];then for i in `cat $mysqlbakpath/1.txt` do echo "recovey $i" $mysql_e -u$dbuser -p$dbpass -e "create database $i;" $mysql_e -u$dbuser -p$dbpass $i < $mysqlbakpath/$i.sql done fi #end Import mysql
宝塔面板环境
#!/bin/bash dbuser='root' dbpass='kp5hwmzy' mysqldata='/www/server/data' mycnf='/etc/my.cnf' mysql_e='/www/server/mysql/bin/mysql' mysqldump_e='/www/server/mysql/bin/mysqldump' mysqlbakpath="/home/bkmysql/" function stop_mysql(){ service mysqld stop if [ $? -ne 0 ];then ps -e|grep mysql|awk '{print $1}'|xargs kill -9 fi } mkdir -p $mysqlbakpath sed -i -e '/\[mysqld\]/a innodb_force_recovery=6' $mycnf stop_mysql service mysqld start #start dump innodb mysql if [ $? -eq 0 ];then cd $mysqldata # 注意宝塔有时候没有分表为ibd.删除下面ls开头一行 # 在/home/bkmysql/下创建1.txt ,内容为数据库列表,一行一个 # 可以mysql登录数据库后,执行show databases;获取.注意删除mysql test等无用数据库 ls *\/*.ibd -h|awk -F'/' '{print $1}'|uniq|grep -v 'mysql' > $mysqlbakpath/1.txt for i in `cat $mysqlbakpath/1.txt` do echo "dump $i" $mysqldump_e -f -u$dbuser -p$dbpass $i > $mysqlbakpath/$i.sql done fi #end dump innodb mysql #start bkup innodb mysql cd $mysqldata stop_mysql mv -f ibdata1 ib_logfile0 ib_logfile1 $mysqlbakpath for i in `cat $mysqlbakpath/1.txt` do mv -f $i $mysqlbakpath done #end bkup innodb mysql sed -i -e '/innodb_force_recovery=6/d' $mycnf service mysqld start #start Import mysql if [ $? -eq 0 ];then for i in `cat $mysqlbakpath/1.txt` do echo "recovey $i" $mysql_e -u$dbuser -p$dbpass -e "create database $i;" $mysql_e -u$dbuser -p$dbpass $i < $mysqlbakpath/$i.sql done fi #end Import mysql`
» 本文链接地址:https://mydns.vip/4856.html
最新评论
麻烦发下检测工具
让我下载
非常好