Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to store a pretty large JSON object in MySQL

I'm building a Laravel app the core features are driven with rather large JSON objects. (the largest ones are between 1000-1500 lines).

I know there are better data base choices than MySQL for storing files and blocks of data, but for various reasons I will need to use MySQL for the application.

So my question is, how to I store my JSON objects most effective in MySQL? I will not need to do any queries on the column that holds the data, there will be other columns for identifying it. Something like this:

id, title, created-at, updated-at, JSON-blobthingy

Any ideas?

like image 509
Christoffer Avatar asked Nov 25 '15 09:11

Christoffer


People also ask

Can you store JSON objects in MySQL?

MySQL supports a native JSON data type defined by RFC 7159 that enables efficient access to data in JSON (JavaScript Object Notation) documents. The JSON data type provides these advantages over storing JSON-format strings in a string column: Automatic validation of JSON documents stored in JSON columns.

What is the drawback of JSON in MySQL?

The drawback? If your JSON has multiple fields with the same key, only one of them, the last one, will be retained. The other drawback is that MySQL doesn't support indexing JSON columns, which means that searching through your JSON documents could result in a full table scan.

How large is too large for JSON?

One of the more frequently asked questions about the native JSON data type, is what size can a JSON document be. The short answer is that the maximum size is 1GB.


3 Answers

You could compress the data before inserting it if you don't need it searchable. I'm using the 'zlib' library for that

like image 128
Bractar Avatar answered Oct 30 '22 09:10

Bractar


  • You could use the JSON data type if you have MySQL version 5.7.8 or above.
  • You could store the JSON file on the server, and simply reference its location via MySQL.
  • You could use also one of the TEXT types.
like image 33
Wayne Whitty Avatar answered Oct 30 '22 09:10

Wayne Whitty


The best answer i can give is to use MySQL 5.7. On this version the new column type JSON are supported. Which handles large JSON very well (obviously).

https://dev.mysql.com/doc/refman/5.7/en/json.html

like image 35
ins0 Avatar answered Oct 30 '22 09:10

ins0