数据库总是 Web 数据存储的解决方案吗?

发布于 2024-08-18 04:13:19 字数 311 浏览 2 评论 0原文

我没有任何数据库方面的经验,但打算学习它并在我计划的网络项目中使用它。

不过,我的一个朋友建议我数据库的使用应该比我计划的更广泛。他相信将几乎所有数据保存在数据库中,我发现数据库对于用户数据(只是很小的数据)和页面内容数据等(不仅仅是非常小的数据)来说是最方便的在静态文件中 - 没有任何知识来建立该假设。

  • 更好的解决方案是什么?数据库中的最少数据,还是我能找到有效存储的方法?
  • 使用静态文件和使用数据库有性能差异吗?
  • 最佳解决方案是否取决于一般站点流量?

我打算结合使用 PHP 和 MySQL。

I haven't got any experience with databases, but intends to learn it and use it on a web project I'm planning.

Though, I've got advice from a pal of mine that the use of databases should be quite more extensive than I planned. He believes in keeping almost all of the data in databases, where I find that databases are most convenient regarding perhaps user data (just tiny pieces of data), and page content data and the like (everything that's not just very tiny pieces of data) in static files - without having any knowledge to build that assumption upon.

  • What would be the better solution? Minimum data in databases, or as much as I can find ways to store in them effectively?
  • Is there a performance difference between the use of static files and databases?
  • Would the best solution depend on general site traffic?

I intend to use a combination of PHP and MySQL.

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

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

发布评论

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

评论(7

我早已燃尽 2024-08-25 04:13:19

如果您希望能够根据多个参数搜索特定数据,那么您确实需要使用数据库。 SQL 语言为您提供了 WHERE 子句这。此外,每当要创建和更新数据时,数据库都是最佳选择,因为它提供了约束以在一定程度上确保数据的唯一性。此外,数据之间的关系最好由数据库管理(使用外键等)。

例如,用户配置文件最好存储在数据库中。用户控制的输入也必须存储在数据库中。另一方面,服务器端包含/模板文件最好作为普通文件存储在服务器的本地磁盘文件系统中,因为不需要在其中搜索。如果您想将文件名与更多(元)信息(例如菜单/子菜单)“链接”,您最终可以将文件名存储在数据库中。这同样适用于二进制文件(图像、下载等),您不希望将它们保存在数据库中,除非您想要(极高)高度的可移植性。

If you want to be able to search specific data based on several parameters, then you really need to use a database. The SQL language namely offers you the WHERE clause exactly for this. Also whenever data is to be created and updated, the database is the best choice, because it provides constraints to ensure the uniqueness of the data to certain degree. Also relations between data is best to be managed by the database (using foreign keys and so on).

For example an user profile is best to be stored in a database. Also user-controlled input must be stored in a database. Server-side include/template files are on the other hand best to be stored as normal files in the server's local disk file system, because there's no need to search in it. You can eventually store filenames in the database if you want to "link" them with some more (meta)information (e.g. menu/submenu). The same applies to binary files (images, downloads, etc), you don't want to have them in a database, unless you want a (extremely) high degree of portability.

傲性难收 2024-08-25 04:13:19

数据库并不是持久数据存储的唯一方式,它们只是最常见的方式。

有些文档/博客引擎根本不使用数据库。当创建、更改或评论页面时,会创建或修改静态 html 文件。例如,可移动类型

同样,您可以拥有纯内存存储系统,如果系统关闭,内存中的数据将被简单地重建。或者内存内容被转储然后恢复,并且不涉及数据库。这通常在具有极高吞吐量或需要极低(微秒级)延迟的系统中完成。

您的问题无法真正得到回答,因为您所问的所有问题的答案都是“视情况而定”,并且无论您如何做,都可能使其发挥作用。

我要说的是:在真正遇到问题之前,不要太担心性能。您遇到的大多数性能问题可能都归结为数据库中的索引和主键。

PHP 和 MySQL 是一个不错的选择。

Databases aren't the only means of persistent data storage, they're simply the most common.

There are document/blogging engines that don't use databases at all. When a page is created, changed or commented on a static html file is created or modified. For example, Movable Type.

Likewise you can have purely in-memory storage systems where if the system is turned off the in-memory data is simply reconstructed. Or memory contents are dumped then restored and no database is involved. This is typically done in systems with an extremely high throughput or that requires extremely low (microsecond level) latency.

Your question can't really be answered because the answer to everything you've asked is "it depends" and you can probably make it work however you do it.

I will say this: don't be too concerned about performance until you actually have a problem. Most performance problems you'll encounter will probably come down to indexes and primary keys in the database.

PHP and MySQL is a fine choice.

一影成城 2024-08-25 04:13:19

数据库是保存严格数据的正确位置。平面文件的索引速度根本无法与数据库中的数据几乎相同。另一方面,建立数据库将需要更多的学习收入。

像照片这样的二进制数据在数据库中并不是那么好。

The database is the right place to keep things that are strictly data. Flat files simply cannot be indexed with nearly the same speed as data in a database. On the other hand, setting the database up will require more learning earning.

Binary data like photos isn't so great in databases.

最冷一天 2024-08-25 04:13:19
  • 我会说:数据库中的一切。数据库针对此类事情进行了优化。大多数博客软件也使用数据库来存储内容,这是安全的。编辑:哦,二进制文件确实比文件更好。而且 MySQL 也可以安全地处理它们。如果您有 1 张照片,则可以将其存储在数据库中(因为它更容易维护),但如果您托管 10,000 张照片:请改用文件,并在数据库中保留文件的引用(它们的位置、 ETC。)。
  • 当然:数据库再次被优化。在幕后,数据库使用文件:但您不必再关心这个了。
  • MySQL 数据库对于一般网站流量来说绝对没问题。

PHP和MySQL是不错的选择。

  • I would say: everything in the database. Databases are optimized for these kinds of things. Most blogging software also use databases for content, it's safe. Edit: oh, binary files are indeed better as files. But also MySQL can handle them safely. If you have like 1 photo, it's okay to store it in the database (since it's easier to maintain), but if you host, say, 10.000 photos: use files instead, and keep reference of the files in the database (their location, etc.).
  • Absolutely: databases are, again, optimized. Under the hood, a database uses files: but you don't have to care about this anymore.
  • MySQL database is absolutely fine for general site traffic.

PHP and MySQL is a good choice.

柏林苍穹下 2024-08-25 04:13:19

此外,如果数据操作需要事务,数据库几乎总是唯一好的解决方案。

Also if the data manipulation requires transactions, databases are almost always the only good solutions.

情丝乱 2024-08-25 04:13:19

Mysql是常见的具有数据完整性的数据库之一。如果你计划存储大量数据,最好使用mysql。使用数据库还应考虑安全性。 Mysql 非常安全且易于使用,您还可以在网上搜索一些更好的文档和示例。

Mysql is one of the common databases with data integrity. If you've planned to store a large data, mysql is best to use. Security should also be considered in using database. Mysql is much secure and easy to use, you can also search all over the net for some better documentation and examples.

一影成城 2024-08-25 04:13:19

在我看来 - 你需要一个理由不将数据存储在数据库中。 |但我认为您还应该考虑非关系数据库,例如 google datastore http:// code.google.com/appengine/docs/python/datastore/ 或其他类似的内容。

In my opinion - you need a reason no to store data in the database. |But I think you should also consider non-relation databases like google datastore http://code.google.com/appengine/docs/python/datastore/ or other similar things.

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