暗红色网站,小程序源码安装,狭义的网络营销是什么,网站开发后端语言采用binlog日志的好处掌控所有更改操作,必要时可用于恢复数据数据库主从复制的必要条件[linyouyilocalhost~]# vim /etc/my.cnf[mysqld].. ..log-binmysql-bin //启用二进制日志#xff0c;并指定前缀.. ..[linyouyidbsvr1 ~]# service mysqld restart确认binlog日志文件新启用…采用binlog日志的好处掌控所有更改操作,必要时可用于恢复数据数据库主从复制的必要条件[linyouyilocalhost~]# vim /etc/my.cnf[mysqld].. ..log-binmysql-bin //启用二进制日志并指定前缀.. ..[linyouyidbsvr1 ~]# service mysqld restart确认binlog日志文件新启用binlog后每次启动MySQl服务都会新生成一份日志文件[linyouyilocalhost~]# ls /var/lib/mysql/mysql-bin.*/var/lib/mysql/mysql-bin.000001 /var/lib/mysql/mysql-bin.index清除binlog日志删除早前指定版本的binlog日志RURGE MASTER LOGS TO binlog日志删除所有binlog日志,重新新建日志RESET MASTETR分析binlog日志使用mysqlbinlog工具格式:mysqlbinlog [选项] 日志文件常用选项--start-datatimeYYYY-mm-dd HH:MM:SS--stop-datatimeYYYY-mm-dd HH:MM:SS--start-position起止位置--stop-positon结束位置[linyouyilocalhost ~]# mysqlbinlog /var/lib/mysql/mysql-bin.000002[linyouyilocalhost~]# mysqlbinlog --start-datetime2018-10-20 23:30 /var/lib/mysql/mysql-bin.000002利用binlog恢复数据基本方法使用mysqlbinlog提取历史SQL操作通过管道交给mysql命令重做案例重做第一份binlog所记录的更改操作执行指定Pos节点范围内的sql命令恢复数据根据上述日志分析只要恢复从2018-10-12 20:40:50到2018-10-20 23:15:50之间的操作即可。可通过mysqlbinlog指定时间范围输出结合管道交给msyql命令执行导入重做[linyouyiloclahost ~]# mysqlbinlog \--start-datetime2018-10-12 20:40:50\--stop-datetime2018-10-20 23:15:50\/var/lib/mysql/mysql-bin.000002 | mysql -u linyouyi -pEnter password:若是全部重做[linyouyiloclahost~]# mysqlbinlog /var/lib/mysql/mysql-bin.000002 | mysql -u linyouyi -pEnter password:mysql备份工具mysqlhotcopy不足仅适用于MyISAM引擎的数据库备份过程中,数据插入和更新操作都会被挂起mysqldump不足效率较低,备份和还原速度慢备份过程中,数据插入和更新操作会被挂起XtraBackup工具在线热备份工具备份过程中不锁表,适合生产环境适用支持整体备份和增量备份组件一xtrabackup:C程序,支持InnoDB和XtraDB,不能备份数据表结构组件二innobackupex:以Perl脚本封装xtrabackup,还支持MyISAM,能备份数据表结构xtrabackup基本选项基本选项解释--backup执行备份操作--target-dir备份到目标文件夹--datadir备份的原始文件夹(Mysql库的位置)--prepare准备恢复数据--increamental-basedir增量备份时,指定参照的完整备份路径--incremental-dir准备恢复目录时,指定增量备份的路径1)使用XtraBackup执行数据库备份[linyouyilocalhost~]# mkdir -p /backup/mysql[linyouyilocalhost~]# xtrabackup_56 –backup --datadir/var/lib/mysql/ --target-dir/backup/mysql/2)确认备份好的文件数据[linyouyiloclahost~]# ls /backup/mysql/3)做一个增量备份(基于前一步的完整备份)[linyouyilocalhost ~]# xtrabackup_56 --backup \ #xtrabackup_55 是5.5版本,xtrabackup_56是5.6版本--datadir/var/lib/mysql/\--target-dir/backup/inc01/\--incremental-basedir/backup/mysql/确认备份好的文件数据[linyouyilocalhost~]# ls /backup/inc01/对比完整备份、增量备份的大小[linyouyilocalhost~]# du -sh /backup/mysql/ /backup/inc01/11M/backup/mysql/ //完整备份的大小264K /backup/inc01/准备用于恢复的数据库目录以/backup/mysql/可用来重建MySQL服务器。这种情况下官方建议连做两次--prepare以确保数据一致性[linyouyilocalhost ~]# xtrabackup_56 --prepare --target-dir/backup/mysql/[linyouyilocalhost~]# xtrabackup_56 --prepare --target-dir/backup/mysql/准备恢复“完整备份增量备份”以/backup/mysql/用来重建MySQL服务器但这种情况下需提前合并相关增量备份的数据先准备完整备份目录添加--apply-log-only仅应用日志[linyouyiloclahost ~]# xtrabackup_56 --prepare --target-dir/backup/mysql --apply-log-only然后整合增量备份的数据通过--incremental-dir选项指定增量位置[linyouyilocalhost ~]# xtrabackup_56 --prepare \--target-dir/backup/mysql --apply-log-only \--incremental-dir/backup/inc01至此,已经把全量备份和增量备份合并了接着停止数据库,删除/var/lib/mysql/下的内容,拷贝数据[linyouyilocalhost home]# systemctl stop mariadb//删除/var/lib/mysql/下的内容[linyouyilocalhost home]# rm -rf /var/lib/mysql/*#[linyouyihadoop01 home]# innobackupex --defaults-file/etc/my.cnf --copy-back /home/mysql --userlinyouyi --password123456[linyouyilocalhost home]# xtrabackup --copy-back --target-dir/home/mysql[linyouyilocalhost home]# chown -R mysql:mysql /var/lib/mysql/[linyouyilocalhost home]# systemctl start mariadb至此,数据已经恢复成功