duankang5882 2019-04-22 03:55
浏览 93

使用PHP脚本备份具有3个月大的数据的特定表

I would like to back up one of my database tables, abc using PHP.

One of the column is timestamp. I would like to back up the table that is 3 months old into filename.sql.gz and delete the data from the table. Keep latest 3 months data on the table.

If possible the output file only has the INSERT query.

  • 写回答

1条回答 默认 最新

  • duanliaolan6178 2019-04-22 04:35
    关注

    You first need to go through the PHP+database integration tutorials. You can achieve above in mysql query itself. You can use PHP as well...you have to write your own code for this simple task. following are the steps that I will follow in completing this tasks, you can modify the steps according to your requirements...

    you have not mentioned which database you are using, am assuming its Mysql/mariadb

    1. Connect database (proper access required), some PHP file management knowledge also necessary

    2. Based on timestamp, you should write a query which can pull the old data and write it to a .sql file (plenty of questions have already been asked on this topic in stackoverflow)

    3. On success of STEP 2, you can perform DELETE operation

    4. While doing this activity, make sure that no other process/queries are running on this database/table.

    5. Script must include TRANSACTION START/BEGIN, COMMIT and ROLLBACK

    6. If you want output file in INSERT query then BATCH INSERT is required. Refer this to get an idea how batch query looks like (How to do a batch insert in MySQL) You can write a custom PHP function to generate BATCH implementation.

    7. No need to touch the data that you want to keep, will remain as it is

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?