MySQL与JSON-为什么? [英] MySQL vs. JSON - Why?

查看:65
本文介绍了MySQL与JSON-为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个小的网络应用程序/游戏.哪个更好:MySQL表或json文件?它们都存储信息.它们都可以由PHP解析.优点/缺点是什么?

I'm designing a little web-app/game. What would be better: MySQL tables or json files? They both store information. They can both be parsed by PHP. What are the advantages/disadvantages?

这是我的意思:

username | password
-------------------
seefour  | abc123

vs.

{
  "username":"seefour",
  "password":"abc123"
}


哇,距离我问这个问题只有3年了,很惊讶地看到,自问这个问题以来,我已经成熟了多少.从未来的我到过去的我,这就是为什么两者都不起作用的原因. (以防当时像我这样的任何天真的人都可以参考这个)


Wow, It's been just 3 years since I asked this question and it's surprising to see how much I've matured since when I asked this question. From a future me to the past me, this is why the two don't work. (In case anybody naive like me at the time can refer to this)

我曾经认为两者是可以互换的,因为它们在很大程度上都是存储信息的方式,尽管当时存储和使用JSON文件对我来说比较容易.数据库是独立的软件,可以更快地检索数据,并且不会随着时间的推移而变得肿.同样,将所有数据都存储在一个或两个文件中,很容易导致最终数据被盗或丢失,因为这样做对数据库来说要安全得多.从根本上讲,数据不应成为您代码的一部分;它应该与您的代码一起使用.

I used to think the two were interchangeable because they were both pretty much ways of storing information, although storing and using JSON files was easier to me at the time. Databases are separate pieces of software that make retrieving data much faster and don't end up being bloated over time. Also, carrying all the data in one or two files makes it dangerously easy to end up getting your data stolen or lost, where as a database is much more secure with those. Fundamentally, data shouldn't be part of your code; it should be a separate thing that your code works with.

此外,您还将在接下来的几年中学习有关哈希和盐腌的知识,所以请不要将密码存储在纯文本中!

Also, you'll learn about hashing and salting a couple of years down the line, so don't store passwords in plain text!

推荐答案

说真的,MySQL是一个数据库,而JSON不是,所以正确的答案是MySQL,毫不犹豫. JSON只是一种语言,几乎没有. JSON从未被设计来处理诸如并发连接或任何类型的数据操作之类的事情,因为它自己的功能是表示而不是管理.

To be really blunt about, MySQL is a database while JSON is not, so the correct answer is MySQL, without hesitation. JSON is just a language, and barely even that. JSON was never designed to handle anything like concurrent connections or any sort of data manipulation, since its own function is to represent data, not to manage it.

因此,请使用MySQL存储数据.然后,您应该使用某种编程语言来读取该数据库,并将该信息作为JSON发送,而不是将任何内容实际存储在JSON中.

So go with MySQL for storing the data. Then you should use some programming language to read that database, and send that information as JSON, rather than actually storing anything in JSON.

如果将数据存储在文件中(无论是JSON格式还是其他格式),由于数据库开始用于同一事物,您将遇到人们不再担心的各种问题.大小限制,锁,命名.当您拥有一个用户时,这已经足够了,但是当您添加更多用户时,您将开始解决许多问题,最终可能会写一个整个数据库引擎来为您处理文件而最终本来可以只使用一个实际的数据库.

If you store the data in files, whether in JSON format or anything else, you will have all sorts of problems that people have stopped worrying about since databases started being used for the same thing. Size limitations, locks, name it. It's good enough when you have one user, but the moment you add more of them, you'll start solving so many problems that you would probably end up by writing an entire database engine just to handle the files for you, while all along you could have simply used an actual database.

这篇关于MySQL与JSON-为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆