简体   繁体   English

DB还是平面文件?

[英]DB or flat file?

Just one little question. 只是一个小问题。 Shall i put the HTML textarea content into a DB or a flat file? 我应该将HTML textarea内容放入DB或平面文件中吗? The textarea content can be very long (like an article or a project). textarea内容可能很长(如文章或项目)。

Thanks for helping. 谢谢你的帮助。 Silvio. 西尔维奥。

Use text type instead of string, varchar type in db. 在db中使用文本类型而不是字符串,varchar类型。

Note :-Text fields in mysql are limited to 65kb 注意 :mysql中的文本字段限制为65kb

EDIT 编辑

OR You should look at using MySQL's LONGBLOB or LONGTEXT data type. 或者你应该看看使用MySQL的LONGBLOB或LONGTEXT数据类型。 They can store up to 4 gigabytes of binary or textual data, respectively. 它们可以分别存储多达4千兆字节的二进制或文本数据。

Database without a doubt. 数据库毫无疑问。

There's not much point in flat files because when you start expanding which you will do then you have to create more files and it's easier to lose track. 平面文件没有多大意义,因为当你开始扩展时,你必须创建更多的文件,并且更容易失去跟踪。

Start with a database and when you grow you can do things much faster and more complex selections by using structured query language the name says it all. 从数据库开始,随着您的成长,您可以通过使用structured query language来更快,更复杂地进行选择。

Here are some pros and cons off the top of my head (I've done it both ways with varying levels of success): 这里有一些优点和缺点(我已经两种方式完成了不同程度的成功):

Database Pros 数据库优点

  • Well known model for reading / writing data. 众所周知的读/写数据模型。
  • If the rest of your application is based on a database, this solution fits nicely. 如果您的应用程序的其余部分基于数据库,则此解决方案非常适合。
  • The db has concurrency mechanisms already in place. db已经有了并发机制。
  • As long as you back up your database, your documents are backed up to (and in sync with the state of your database). 只要备份数据库,就会备份文档(并与数据库的状态同步)。

Database Cons 数据库缺点

  • Theoretically, it is less efficient to pull a file from a database than directly from the file system. 从理论上讲,从数据库中提取文件的效率低于直接从文件系统提取文件的效率。 The db server has to read from disk, translate into its network protocol, etc. 数据库服务器必须从磁盘读取,转换为其网络协议等。
  • The serving of these files from the db is a potential scalability bottleneck if only using one database server. 如果仅使用一个数据库服务器,则从db提供这些文件是潜在的可伸缩性瓶颈。

Flat File Pros 平面文件优点

  • Dirt simple operations: Write, Delete, Read. 污垢简单操作:写入,删除,读取。
  • Presumably low overhead. 据推测,开销很低。 If serving from web, the server can just be pointed to the files. 如果从Web提供服务,则只需指向服务器即可。

Flat File Cons 平面文件缺点

  • You have to deal with concurrency operations (what if one user wants to write to the file while another is reading, etc). 您必须处理并发操作(如果一个用户想要写入文件而另一个用户正在阅读,等等)。 This may or may not be an issue in your case. 在您的情况下,这可能是也可能不是问题。
  • It's one more type of information to back up / keep in sync / maintain. 这是备份/保持同步/维护的另一种信息。
  • You have to deal with security of the files as a separate issue from the rest of the data in the database. 您必须将文件的安全性作为与数据库中其余数据分开的问题来处理。

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

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