免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 6613 | 回复: 12
打印 上一主题 下一主题

关于LINUX下MYSQL命令备份 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-10-31 15:20 |只看该作者 |倒序浏览
想请问一下有没有关于LINUX用命令恢复数据的教程 就是用mysqldump和mysqlbinlog,我有点不懂得就是mysqldump -uroot -ppasswd -l -F mysql > mysql.sql。这里用了两个参数一个是“-l”和“-F”我想知道这两个参数的意思,好像-F是生成新的日志文件,还有就是我备份别的数据的时候还需要加“-F”不,还有就是mysqlbinlog这个命令来恢复数据,有些时候有很多日志,应该如何选择哪个日志文件。如何知道哪个日志文件是哪个数据库的。

论坛徽章:
0
2 [报告]
发表于 2011-10-31 18:54 |只看该作者
回复 1# system71


    参数mysqldump --help看看就明白了,所有的数据库的binlog都存放在一起,你能可以通过恢复的时候指定要恢复的库,至于用才用什么时候或者是binlog的什么位置恢复,得看你出现故障的时间或者是log位置,具体的参数请参考:--start-datetime,--start-position,--stop-datetime,--stop-position。

论坛徽章:
0
3 [报告]
发表于 2011-10-31 19:36 |只看该作者
回复 2# 飞鸿无痕


    我就是没看懂啊,好多小细节都不懂。

论坛徽章:
0
4 [报告]
发表于 2011-11-01 10:24 |只看该作者
回复 1# system71


   
--flush-logs, -F

          Flush the MySQL server log files before starting the dump. This option requires the RELOAD privilege. Note that if you use this option in combination with the
          --all-databases (or -A) option, the logs are flushed for each database dumped. The exception is when using --lock-all-tables or --master-data: In this case, the
          logs are flushed only once, corresponding to the moment that all tables are locked. If you want your dump and the log flush to happen at exactly the same moment,
          you should use --flush-logs together with either --lock-all-tables or --master-data.

          一般在全数据库一起备份的时候使用这个,刷新日志就是会产生一个新日志,这样你在恢复的时候就很清楚的知道从哪开始备份,而不用去指定--start-time等参数。你不太清楚的是,binlog是全局的,它并不区分是哪个库,所以
如何知道哪个日志文件是哪个数据库的。
的想法是不对的。
   
·  --lock-all-tables, -x

          Lock all tables across all databases. This is achieved by acquiring a global read lock for the duration of the whole dump. This option automatically turns off
          --single-transaction and --lock-tables.

       ·  --lock-tables, -l

          Lock all tables before dumping them. The tables are locked with READ LOCAL to allow concurrent inserts in the case of MyISAM tables. For transactional tables
          such as InnoDB and BDB, --single-transaction is a much better option, because it does not need to lock the tables at all.

          Please note that when dumping multiple databases, --lock-tables locks tables for each database separately. Therefore, this option does not guarantee that the
          tables in the dump file are logically consistent between databases. Tables in different databases may be dumped in completely different states.

       -l是不太保险的,如果你要一起备份很多库,他是对不同的库是分别锁表的,就是当前备份哪个他就锁哪个,不能保证备份文件中不同库中的表逻辑上一致,可能他们处于完全不同的状态,所以最好使用-x,如果表全都是innodb的话,使用 --single-transaction是最好的,单一事务,他会保证备份的数据都是一致的。

论坛徽章:
0
5 [报告]
发表于 2011-11-01 10:34 |只看该作者
回复 3# system71

看不懂就做实验,做了实验就明白了,呵呵!

论坛徽章:
0
6 [报告]
发表于 2011-11-02 09:05 |只看该作者
回复 5# 飞鸿无痕


    好吧你赢了,你就不能写一个例子出来?大哥。公司需要每5天完整备份一次每天增量备份一次,您老能举例写一下么?

论坛徽章:
0
7 [报告]
发表于 2011-11-02 09:23 |只看该作者
回复 6# system71

每5天使用mysqldump做一次全库备份,做全库备份的时候使用--flush-logs,然后每天先使用flush logs命令刷新log后,备份从全库备份的时间到你flush logs时间段的二进制日志作为增量备份就可以了。不知道我这么说算不算说清楚了。呵呵。

论坛徽章:
2
摩羯座
日期:2014-05-29 17:38:40数据库技术版块每日发帖之星
日期:2016-08-05 06:20:00
8 [报告]
发表于 2011-11-02 12:08 |只看该作者
其实,你可以搜索下mysql备份方案,网上文档很多,详细的步骤,不过,建议你看看手册上关于备份的部分

论坛徽章:
0
9 [报告]
发表于 2011-11-02 14:05 |只看该作者
回复 7# 飞鸿无痕


    然后每天先使用flush logs命令刷新log后   请问这句用命令怎么实现。?
我写个大楷语句你老看看,
mysqldump -uroot -p123456 -l -F mysql > mysql.sql
这是完成备份的时候生成的一个bin文件,那么每天生成一个日志文件应该怎么执行呢,应该用什么语句呢

论坛徽章:
0
10 [报告]
发表于 2011-11-02 16:28 |只看该作者
回复 9# system71

登录到mysql,执行flush logs,
或者直接用mysql -uusername -ppassword -e "flush logs" 命令刷新binlog。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP