工具
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| /app/service/mysql/bin/mysql -uroot -p'aU$rh@^S8BgY' ./mysqldump -uroot -p'aU$rh@^S8BgY' --master-data --all-databases > master.sql
CREATE TABLE `Z_Demo` ( `NAME` varchar(64) COLLATE utf8_bin NOT NULL, `REV` int DEFAULT NULL, PRIMARY KEY (`NAME`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin;
DROP TABLE Z_Demo; scp master.sql app@172.24.140.68:/app/temp/ /app/service/mysql/bin/mysql -uroot -p'aU$rh@^S8BgY' < /app/temp/master.sql /app/service/mysql/bin/mysqldump -uroot -p'aU$rh@^S8BgY' wb > /app/temp/wb.sql /app/service/mysql/bin/mysql -uroot -p'aU$rh@^S8BgY' wb < /app/temp/wb.sql mysql -uwb -p'WB@45678' mysql -uedm_base -p'tn2qz3WS*uC'
/app/service/mysql/bin/mysql -uroot -p'aU$rh@^S8BgY' GRANT ALL PRIVILEGES ON wb_etl.* TO 'wb'@'%'; FLUSH PRIVILEGES; /app/service/mysql/bin/mysql -h172.24.140.69 -P3306 -uwb -p'WB@45678' -e "use wb_etl"
|
mysqldump & mysqlbinlog
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| #!/bin/bash
backupDir=/usr/local/work/backup/daily
mysqlDir=/var/lib/mysql
logFile=/usr/local/work/backup/bak.log
BinFile=/var/lib/mysql/mysql-bin.index
mysqladmin -uroot -p123456 flush-logs
Counter=`wc -l $BinFile |awk '{print $1}'` NextNum=0
for file in `cat $BinFile` do base=`basename $file` echo $base NextNum=`expr $NextNum + 1` if [ $NextNum -eq $Counter ] then echo $base skip! >> $logFile else dest=$backupDir/$base if(test -e $dest) then echo $base exist! >> $logFile else cp $mysqlDir/$base $backupDir echo $base copying >> $logFile fi fi done echo `date +"%Y年%m月%d日 %H:%M:%S"` $Next Bakup succ! >> $logFile
|
xtrabackup
https://www.percona.com
Navicat
所有
保证版本一致的情况下直接复制复制数据目录也行
备份
1
| mysqldump -u root -p --all-databases > /tmp/db.sql
|
恢复
1 2 3
| source /tmp/db.sql; 或 mysql -uroot -p < /tmp/db.sql
|
按库
使用 Navicat Premium 备份恢复更加简便
按表
备份
右键要备份的表,转存 SQL 文件
恢复
如果需要恢复,删除新表,运行上次转存出来的表即可