存储数据用mysql好还是用文件好?

发布于 2024-08-16 09:28:16 字数 55 浏览 5 评论 0原文

我想知道用mysql好还是用文件来存储数据好?什么更安全,什么更快?我说的是php和mysql。

I'm wondering if it's better to use mysql or use files to store data? What is safer, what is faster? I'm talking about php and mysql.

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

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

发布评论

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

评论(4

悲喜皆因你 2024-08-23 09:28:16

这完全取决于您的要求和设置。

对于不需要复杂查询的少量数据,文件速度更快。站点缓存就是一个例子。

对于更大的数据集或具有更多结构的数据集,数据库将使您能够以更高级的方式查询数据。

在安全方面,文件可以受到保护(使用权限)并存储在Web根目录之外。数据库可以锁定到某些主机,并且可以拥有具有不同角色/权限的用户。

It completely depends on your requirements and setup.

For small amounts of data that doesn't require complex querying, files are faster. Site caches are one example.

For larger data sets or sets with more structure, a database will enable you to query your data in more advanced ways.

In terms of safety, files can be protected (using permissions) and stored outside the web root. Databases can be locked to certain hosts and can have users with different roles/permissions.

臻嫒无言 2024-08-23 09:28:16

如前所述,这取决于数据,也取决于您当前的瓶颈。
如果您的应用程序运行在 IO 资源已经不足的服务器上,那么无论如何您可能更喜欢网络类型存储。

安全问题更多地与设置和良好实践相关,而不是与所使用的技术相关。如果您编写文件,则需要确保它们不可下载。如果您使用数据库,则需要处理 SQL 注入等问题...

我想强调的是,您并不局限于文件和关系数据库。

您还可以使用 memcached 将数据存储在内存中(例如,非常适合缓存)。
NOSQL 数据库,例如 Redis 也是一个选项。

  • 数据库(即MySQL):
    优点:可搜索,可以处理复杂的结构化数据,可以托管在不同的服务器上,持久
    缺点:慢
    典型用途:业务数据存储
  • 文件:
    优点:非常容易设置、相当快、持久
    缺点:不适合处理非常复杂的数据,不可搜索,会消耗服务器主机IO资源,速度不那么
    典型用法:日志文件、模板缓存文件
  • NOSQL(即Redis):
    优点:快速,可以在远程主机上设置,持久
    缺点:不易搜索,不适合强结构化数据
    典型用法:性能黑客(搜索)
  • 内存:
    优点:最快的!,可以在远程主机上设置
    缺点:与 NOSQL 相同 + 不持久
    典型用法:对象缓存

As said, it depends on the data but also on your current bottleneck.
If your application is running on a server that is already short on IO resources, you might prefer in any case a network-type storage.

Security issues are more related to setup and good practices than to the technology which is used. If you write files, you need to make sure they are not downloadable. If you use a database, you need to take care of SQL injection and so on...

I'd just like to stress out that you are not restricted to files and relational Databases.

You can also use memcached to store data in memory (ideal for cache for instance).
NOSQL databases like Redis are also an option.

  • Database (ie MySQL):
    pros: searchable, can handle complex and structured data, can be hosted on a different sever, persistent
    cons: slow
    typical usage: business data storage
  • Files:
    pros: very easy to setup, quite fast, persistent
    cons: not suitable to handle very complex data, not searchable, will consume server host IO resources, not that fast
    typical usage: log files, template cache files
  • NOSQL (ie Redis):
    pros: fast, can be setup on a remote host, persistent
    cons: not easily searchable, not suitable for strongly structured data
    typical usage: performance hacks (search)
  • Memory:
    pros: The fastest one!, can be setup on a remote host
    cons: same as NOSQL + not persistent
    typical usage: object caching
待天淡蓝洁白时 2024-08-23 09:28:16

取决于数据。

除非它真的很微不足道,否则你也可以使用 mysql。确实没有明显的缺点。

Depends on the data.

Unless it is really trivial though, you may as well use mysql. There isn't really an obvious downside.

只怪假的太真实 2024-08-23 09:28:16

一般来说,您需要某种数据库或对象存储来存储您的数据,因为它提供了一个干净的接口来检索您的数据。但是,它很大程度上取决于您尝试存储的数据。

如果您正在制作一个包含用户可修改数据的网站,您可能需要使用 MySQL 或其他一些数据库。如果您只是谈论输入一些文档,那么数据库的开销可能会带来更多麻烦而不是其价值。

为了提供更好的答案,我们需要知道您正在存储什么类型的数据以及您希望如何访问它。

Generally speaking, you will want some sort of database or object store to store your data because it provides a clean interface to retrieve your data. However, it is very dependent upon the data that you are trying to store.

If you are making a website with user modifiable data, you probably want to use MySQL or some other database. If you are just talking about typing up some documents, the overhead of a database is probably more trouble than it's worth.

In order to provide a better answer, we need to know what type of data you are storing and how you want to access it.

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