备份
BakDir=/home/mysql/data #增量备份时复制mysql-bin.00000*的目标目录,提前手动创建这个目录
BinDir=/var/lib/mysql #mysql的数据目录
LogFile=/home/mysql/bak.log
BinFile=/var/lib/mysql/mysql-bin.index #mysql的index文件路径,放在数据目录下
mysqladmin flush-logs
#这个是用于产生新的mysql-bin.00000*文件
Counter=`wc -l $BinFile |awk '{print $1}'`
NextNum=0
#这个for循环用于比对$Counter,$NextNum这两个值来确定文件是不是存在或最新的
for file in `cat $BinFile`
do
base=`basename $file`
#basename用于截取mysql-bin.00000*文件名,去掉./mysql-bin.000005前面的./
NextNum=`expr $NextNum + 1`
if [ $NextNum -eq $Counter ]
then
echo $base skip! >> $LogFile
else
dest=$BakDir/$base
if(test -e $dest)
:#test -e用于检测目标文件是否存在,存在就写exist!到$LogFile去
then
echo $base exist! >> $LogFile
else
cp $BinDir/$base $BakDir
echo $base copying >> $LogFile
fi
fi
done
echo `date +"%Y年%m月%d日 %H:%M:%S"` $Next Bakup succ! >> $LogFile
使用binlog恢复增量备份,恢复过程亦会写入日志文件,如果数据量很大,建议先关闭日志功能
1
mysqlbinlog mysql-bin.000xxxx | mysql -u root -p
冲突
Mycli also reads the [client] section of MySQL’s option file, ~/.my.cnf (on Windows: C:\Users\<username>\.my.cnf). See the example file at the bottom of this page for more information.
1 2 3 4 5 6 7 8
[client] # The client section is read by mycli and all MySQL applications. ..... # Turn on the LOAD DATA INFILE statement local-infile = on
❯ mysql -uroot -p123456 -P3305 k8s_grafana < ~/backup/k8s_grafana_data.sql
test
1 2 3 4
#查出结果复制执行,清空表数据 SELECT CONCAT('truncate table ',TABLE_NAME,';') AS a FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'k8s_grafana' ; #查出结果复制执行,清空表 SELECT concat('DROP TABLE IF EXISTS ', table_name, ';') FROM information_schema.tables WHERE table_schema = 'k8s_grafana';