简体   繁体   English

mysql 中的最佳实践?

[英]best practice in mysql?

我需要在 mysql 中存储某些内容的历史数据(仅过去 7 天) - 我应该为每个额外的列创建一个额外的列还是可以接受的方式是什么?

if you want to store historical data for last 7 days only,如果您只想存储过去 7 天的历史数据,
add a date-time column to store the record creation time-stamp,添加一个日期时间列来存储记录创建时间戳,
and setup a cronjob to periodically remove the records which old than 7 days并设置一个 cronjob 来定期删除超过 7 天的记录

if you are using file-based data (csv),如果您使用基于文件的数据 (csv),
make sure categories data into different date,确保将数据分类为不同的日期,
and each file contains a single date,每个文件都包含一个日期,
use the find command to remove (I assume you are using linux)使用 find 命令删除(我假设您使用的是 linux)

find -type f -mtime 7 -xargs rm {} \;

如果我理解正确,您应该使用列(数据、日期)创建表历史记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM