mySQL 每日从一个表备份到另一个表
如果我有两个具有相同定义的表,我将如何每天备份其中的数据?我可以使用 mySQL Administrator 执行类似的操作
- 每天中午 12:00 将所有行从 main_table 复制到 backup_table
- 如果是增量备份会更好,因为会对 backup_table 中的记录进行一些更改,而我不希望一个新的备份来消除这些更改。
谢谢
If I have 2 tables with the same definition, how would I backup data from it daily? Can I use mySQL Administrator to perform something like this
- At 12:00am everyday, copy all the rows from main_table to backup_table
- It will be preferable if it is incremental backup as some changes will be made to the reccords in backup_table and I don't want a new backup to wipe out those changes.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让我们从这个开始:将数据从一个表复制到同一服务器上的另一个表不是备份。
现在,如果您有 MySQL 5.1.6 或更高版本,您可以使用事件调度程序来安排此类操作。
http://dev.mysql.com/doc/refman/5.1/en /events.html
它应该像运行这样的查询一样简单
(这将复制任何新行,现有行中的更改不会被复制)
至于实际备份,请阅读以下内容:
< a href="http://dev.mysql.com/doc/refman/5.1/en/backup-methods.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.1/ en/backup-methods.html
Let's start with this: Copying data from one table to another on the same server IS NOT a backup.
Now, if you have MySQL 5.1.6 or newer, you can use event scheduler, to schedule such actions.
http://dev.mysql.com/doc/refman/5.1/en/events.html
It should be as simple as running a query like this
(this will copy any new rows, changes in already existing rows will not be copied over)
As far as actual backups go, please read this:
http://dev.mysql.com/doc/refman/5.1/en/backup-methods.html
是的,你绝对可以做到。看一下这个页面:http://dev.mysql。 com/doc/refman/5.0/en/batch-mode.html
如果您仔细编写脚本,那么您不会删除表而只是插入新行,您不必担心丢失数据。如果您为表中的每一行存储了时间戳,那么事情就会变得容易得多。您可以使用时间戳来加载/更新自上次批量运行以来已更改或添加的新行。
但是,在执行插入之前备份当前表始终是最佳实践。如果导入成功,您可以清理备份表。
Yes, you can definitely do that. Have a look at this page: http://dev.mysql.com/doc/refman/5.0/en/batch-mode.html
If you write your script carefully, so that you are not dropping the table and just inserting the new rows you need not worry about losing the data. If you are having a timestamp stored for each row in the table, that makes things a lot easier. You can use the timestamp to load/update the new rows which have been changed or added since the last batch run.
However, its always a best practice to make a backup of the current table before you do the insertion. You can cleanup the backup tables, if the import is successful.