CodexBloom - Programming Q&A Platform

In MySQL 8.0, why am I getting a 'Data too long for column' scenarios when inserting JSON data?

👀 Views: 80 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-28
mysql json insert error sql

I keep running into I've tried everything I can think of but I'm sure I'm missing something obvious here, but I'm working with MySQL 8.0 and trying to insert JSON data into a table, but I'm working with a 'Data too long for column' behavior. The table is defined as follows: ```sql CREATE TABLE my_table ( id INT AUTO_INCREMENT PRIMARY KEY, data JSON NOT NULL ) ENGINE=InnoDB; ``` When I attempt to execute the following insert statement: ```sql INSERT INTO my_table (data) VALUES ('{"name": "John Doe", "age": 30, "city": "New York"}'); ``` It works fine, but when I try a larger JSON object: ```sql INSERT INTO my_table (data) VALUES ('{"name": "John Doe", "age": 30, "city": "New York", "address": {"street": "123 Main St", "zipcode": "10001"}, "tags": ["developer", "mysql", "json", "long data"]}'); ``` I get the following behavior: ``` behavior 1406 (22001): Data too long for column 'data' at row 1 ``` I ensured that the JSON object does not exceed the maximum size limit for a JSON column, which is supposed to be 4GB. I also checked the character set and collation for the table and it is set to utf8mb4. Additionally, I've tried changing the JSON data structure to simplify it, but I still get the same behavior. Is there an internal limit I might be missing, or is there a configuration option that affects the maximum size of JSON data that can be inserted? Any insights on how to resolve this would be much appreciated! Is there a better approach? This is part of a larger CLI tool I'm building. What's the best practice here? Could someone point me to the right documentation?