简体   繁体   English

使用XML和MySQL数据库的差异在哪里? 我应该使用哪个?

[英]Where are the differences using XML and MySQL database? Which should I use?

Well, I know its a bit stupid. 好吧,我知道它有点愚蠢。 If I want to store a large amount of data. 如果我想存储大量数据。 Should I use xml or database(mysql)? 我应该使用xml还是数据库(mysql)?

Why do you choose (that) one? 你为什么选择一个?

What are the pros and cons using xml? 使用xml有什么优缺点?

What are the pros and cons using mysql? 使用mysql有什么优缺点?

Clubpenguin, habbo hotel, those virtual worlds are using xml or mysql?? Clubpenguin,habbo酒店,那些虚拟世界都在使用xml或mysql?

MySQL (or SQL Server, Oracle, DB2, etc.) are database engines: they're specific applications that were built for data storage and processing, and are very good at doing that; MySQL(或SQL Server,Oracle,DB2等)是数据库引擎:它们是为数据存储和处理而构建的特定应用程序,并且非常擅长这样做; they also can run on a different server than the one where your main program is, allowing for load sharing. 它们也可以在与主程序不同的服务器上运行,从而实现负载共享。

XML files are just text files stored on your machine or another one; XML文件只是存储在您的计算机或其他文件上的文本文件; they need to be read, parsed and written to, and only your program can do that. 它们需要被读取,解析和写入,只有你的程序才能这样做。 They'are also really, really inefficient, because of their text nature: reading and parsing a text file is very slow, and modifying it is even worse. 由于它们的文本性质,它们也非常非常低效:读取和解析文本文件非常慢,修改它更糟糕。

XML files are good for storing configuration settings and passing data between different systems, but data storage and processing should definitely live in a proper DBMS. XML文件适用于存储配置设置和在不同系统之间传递数据,但数据存储和处理绝对应该存在于适当的DBMS中。

Also, obligatory Joel Spolsky reference . 此外, 强制性Joel Spolsky参考

Consider if you have an XML document with a nested person element that contains information on each of your users, and you have 3000 users. 考虑一下,如果您的XML文档包含嵌套的person元素,其中包含有关每个用户的信息,并且您有3000个用户。 If you want to pull the information for a single person, you're going to have quite the task of parsing through that huge file to find that person's information. 如果你想为一个人提取信息,那么你将完成解析这个庞大文件的任务,找到那个人的信息。 You might could use some clever seeking to jump around the file, but ultimately there is going to be alot of sequential access. 您可能可以使用一些聪明的搜索来跳转文件,但最终会有很多顺序访问。

With a database you will normally have indexes, which would allow you to very quickly perform searching tasks like the above. 使用数据库,您通常会有索引,这样您就可以非常快速地执行上述搜索任务。 In the above scenario, finding an individual in an indexed table will probably be on the order of 100 times faster. 在上面的场景中,在索引表中查找个人可能会快100倍。

It depends a lot on what kind of data you want to store. 这很大程度上取决于您要存储的数据类型。 If you are storing mostly document oriented stuff, XML can be a good choice. 如果您主要存储面向文档的东西,XML可能是一个不错的选择。 If you are storing lots of small hierarchies, XML is probably better than SQL. 如果要存储大量小型层次结构,则XML可能比SQL更好。 The time to read and parse an XML file is definitely more that the time needed to get a simple query out of a database. 读取和解析XML文件的时间肯定是从数据库中获取简单查询所需的时间。 But if you have data that do not fit naturally in a database, the cost of query could go up dramatically and actually become more than just using XML files. 但是,如果您的数据不能自然地适应数据库,那么查询的成本可能会急剧上升,实际上不仅仅是使用XML文件。

One other option you could try is using an XML database, for example Xindice ( http://xml.apache.org/xindice/ ). 您可以尝试的另一个选项是使用XML数据库,例如Xindice( http://xml.apache.org/xindice/ )。 XML databases are not that much used at the moment, mostly because we dont have good mathematical theories about hierachic databases. XML数据库目前使用的并不多,主要是因为我们没有关于层次数据库的良好数学理论。 But they can be really usefull if you have the right problem ... 但如果你有正确的问题,它们真的很有用......

Markmail.org may surprise you -- it's an xml store. Markmail.org可能会给你带来惊喜 - 它是一个xml商店。

Read Ron Burret ( http://www.rpbourret.com/xml/XMLAndDatabases.htm ) is an great source on the subject. 阅读Ron Burret( http://www.rpbourret.com/xml/XMLAndDatabases.htm )是该主题的重要来源。

This seems more of a StackOverflow question rather than a ServerFault question. 这似乎更像是StackOverflow问题,而不是ServerFault问题。 Anyways.. 无论如何..

If you need random access to data elements, use a real database. 如果需要随机访问数据元素,请使用真实数据库。 If you're just doing batch processing or something, xml will work, but a database is still fine for that too. 如果您只是进行批处理或其他什么,xml将起作用,但数据库仍然可以。

If you don't need to store data with relational properties, you could try a key/value store, or document-oriented database, instead of a RDBMS, for better performance/scalability in exchange for fewer features. 如果您不需要存储具有关系属性的数据,则可以尝试使用键/值存储或面向文档的数据库而不是RDBMS,以获得更好的性能/可伸缩性,以换取更少的功能。

Well, I know its a bit stupid. 好吧,我知道它有点愚蠢。 If I want to store a large amount of data. 如果我想存储大量数据。 Should I use xml or database(mysql)? 我应该使用xml还是数据库(mysql)?

First of all, XML is hierarchic by its nature, while MySQL is relational . 首先, XML本质上是层次结构 ,而MySQL关系型的

If you will store your data as XML document: 如果要将数据存储为XML文档:

<customer>
 <address/>
 <address/>
</customer>

, it's super easy to obtain all addresses of a customer, but not so easy to obtain customers for a given address. ,获取客户的所有地址非常容易,但获取给定地址的客户却不那么容易。

Second, XML is more user-oriented. 其次, XML更加面向用户。 You can easily edit it with your favourite text editor. 您可以使用自己喜欢的文本编辑器轻松编辑它。 In MySQL , it's not so easy. MySQL ,它并不那么容易。

Given all above, if your data are hierarchical, small in size and you need them to be easily editable without any frontend, use XML . 鉴于上述情况,如果您的数据是分层的,尺寸较小,并且您需要在没有任何前端的情况下轻松编辑它们,请使用XML

If your data are relational and you need fast set operations on large quantities of data, use MySQL . 如果您的数据是关系型的,并且您需要对大量数据进行快速设置操作,请使用MySQL

Most big sites are using a database like MySQL. 大多数大型网站都使用像MySQL这样的数据库。

The most important question you need to answer is how you want to access your data. 您需要回答的最重要的问题是您希望如何访问数据。 If you want to have many people looking things up many times a second (eg a popular website), then use a database like mysql. 如果你想让很多人每秒多次查看(例如一个受欢迎的网站),那么使用像mysql这样的数据库。

I would believe it more likely they're using a Fully Fledged DBMS as a backing store, and only generating/parsing XML as an interface. 我相信他们更有可能将完全成熟的DBMS用作后备存储,并且只生成/解析XML作为接口。

XML is imho far too heavy to be used for a high-data store database. XML非常重,无法用于高数据存储数据库。

The Structure is too parse-heavy and even if you had some sort of server which started, parsed, and then ran based on the XML data, the initialization time would be killer, as would be the data reserialization phase every time a write was done. 结构过于严重,即使你有某种服务器启动,解析,然后根据XML数据运行,初始化时间也会很凶,每次写入时都会有数据重新编译阶段。 。

RDBMS's benefit by having much more efficient packed data storage with predictable searching/seeking through records and multiple data-stores and multiple indicies. RDBMS的优势在于具有更高效的打包数据存储,可通过记录和多个数据存储以及多个指标进行可预测的搜索/搜索。

XML is not a database, it's a file format (or, to be more precise, an input or output stream format). XML不是数据库,它是一种文件格式(或者更确切地说,是一种输入或输出流格式)。 It allows you to define your own format using XML's syntax elements and then you can, for example, convert your memory object to an XML stream and save it to disk. 它允许您使用XML的语法元素定义自己的格式,然后您可以将内存对象转换为XML流并将其保存到磁盘。

mySQL is a software product that belongs to the class of products called DBMS (Database managent system). mySQL是一种软件产品,属于称为DBMS(数据库管理系统)的产品类。 DBMSs manage your data and provide various storage, retrieval, indexing, querying, and transactional capabilities. DBMS管理您的数据并提供各种存储,检索,索引,查询和事务功能。

What you need to decide is whether you need a file format or a management system. 您需要决定的是您是需要文件格式还是管理系统。 Depending on that, your choice may be XML (or some other format, eg JSON or a plain-text file) or mySQL (or another relational DBMS, eg MS SQL Server or Oracle -- or may even be a non-relational DBMS). 根据这一点,您的选择可能是XML(或其他一些格式,例如JSON或纯文本文件)或mySQL(或其他关系DBMS,例如MS SQL Server或Oracle - 或者甚至可能是非关系型DBMS) 。

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

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