在 MySQL 中存储时间序列的最佳方式是什么?

发布于 2024-09-25 02:00:39 字数 100 浏览 1 评论 0 原文

我想存储大量时间序列(时间与值)数据点。我更喜欢使用 MySQL 来实现同样的目的。现在我计划将时间序列作为二进制 Blob 存储在 MySQL 中。这是最好的方法吗?最好的方法是什么。

I want to store a large number of Time Series (time vs value) data points. I would prefer using MySQL for the same. Right now I am planning to store the time series as a Binary Blob in MySQL. Is this the best way, what would be the best approach.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

淡笑忘祈一世凡恋 2024-10-02 02:00:39

您应该将值存储为任何类型(int、boolean、char),并将时间存储为日期或包含 UNIX 时间戳的 int,只要更适合您的应用程序即可。

You should store your values as whatever type they are (int, boolean, char) and your times as either date, or int containing the UNIX timestamp, whatever fits your application better.

星星的轨迹 2024-10-02 02:00:39

如果您想使用 mysql 以任何方式处理信息,您应该将其存储为日期类型、数字类型。
我看到的唯一缩放问题(如果您只想存储信息)是额外的磁盘大小。

If you want to process the information in any way using mysql you should store it as a date type, numeric type .
The only scaling issue i see (if you only intend to store the information) is extra disk size.

灯下孤影 2024-10-02 02:00:39

正如 Tom 和 aeon 所说,如果您想对数据执行任何操作(-> 使用 SQL 处理数据),则应该将数据以其本机格式存储在 MySQL 中。

另一方面,如果您不想处理该数据,而只是存储/检索它,那么您将 MySQL 用作 blob 容器,其中每个 blob 都是多个时间/数据点的混乱/组,它不可能是完成这项工作的最佳工具:这就是文件的设计目的。

您可以研究一种混合方法,其中可以存储非结构化数据,但将时间戳存储为离散值。换句话说,一个以时间戳为键的键/值存储。这应该开启了使用 NoSQL 解决方案的可能性,也许您会发现它们更适合(例如,考虑直接在 map/reduce 作业 http://wiki.basho.com/Riak.html" rel="nofollow">Riak 集群)

As both Tom and aeon said, you should store data in its native format in MySQL if you want to do anything with that data (-> process the data with SQL).

If, on the other end, you don't want to work on that data, but just store/retrieve it, then you are using MySQL just as a blob container where every blob is a mess/group of multiple time/data points, and it could not be the best tool for the job: that's what files are designed for.

You could investigate an hybrid approach where you possibly store the data non-structured, but you store timestamps as discrete values. In other words, a key/value store with your timestamps as keys. That should open up the possibility to work with NoSQL solutions and maybe you could find out that they fit better (eg. think about running map/reduce jobs directly on the db in a Riak cluster)

留一抹残留的笑 2024-10-02 02:00:39

根据您的应用程序,可以选择使用 MySQL 的空间数据扩展。然后,您可以使用空间索引来快速查询数据。
要表示时间序列,LineString 类可能是最合适的选择。它表示可用于存储时间和值的元组序列。
这里它说“在世界地图上, LineString 对象可以代表河流。”
创建行字符串很容易:

-- if you see a blob, use Convert( AsText(...) using 'utf8')
SELECT AsText(GeomFromText('LineString(1 1, 2 2, 3.5 3.9)'));

一些入门链接:

https:// /dev.mysql.com/doc/refman/5.1/en/spatial-extensions.html
https://dev.mysql.com/doc/refman /5.1/en/populate-spatial-columns.html

Depending on your application, using the spatial data extensions of MySQL could be an option. You could then use spatial indexing to query the data fast.
To represent a time series, the LineString class might be the most appropriate choice. It represents a sequence of tuples you could use to store time and value.
Here it says that "On a world map, LineString objects could represent rivers."
Creating line strings is easy:

-- if you see a blob, use Convert( AsText(...) using 'utf8')
SELECT AsText(GeomFromText('LineString(1 1, 2 2, 3.5 3.9)'));

Some links to get started:

https://dev.mysql.com/doc/refman/5.1/en/spatial-extensions.html
https://dev.mysql.com/doc/refman/5.1/en/populating-spatial-columns.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文