You probably have strict mode enabled on your server, and not on your local MySQL instance.
Check it this way:
mysql> SELECT @@sql_mode;
+-------------------------------------------------------------------------------------------------------------------------------------------+
| @@sql_mode |
+-------------------------------------------------------------------------------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+-------------------------------------------------------------------------------------------------------------------------------------------+
The above is the default sql_mode for MySQL 5.7.8 and later. It includes strict mode.
One of the effects of strict mode is that if you store a string value or numeric value into a column that isn't large enough to take that value, you get an error. Without strict mode, MySQL inserts the row — but it truncates the value.
Here's a demonstration:
mysql> create table t ( v varchar(10) );
mysql> insert into t set v = 'Now is the time for all good men to come to the aid of their country';
ERROR 1406 (22001): Data too long for column 'v' at row 1
mysql> set sql_mode='';
mysql> insert into t set v = 'Now is the time for all good men to come to the aid of their country';
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> show warnings;
+---------+------+----------------------------------------+
| Level | Code | Message |
+---------+------+----------------------------------------+
| Warning | 1265 | Data truncated for column 'v' at row 1 |
+---------+------+----------------------------------------+
mysql> select * from t;
+------------+
| v |
+------------+
| Now is the |
+------------+
Strict mode is a good thing. It's better to know that your data won't fit, instead of having it get truncated.
You should develop with a local MySQL instance that has the same version and the same sql_mode as the MySQL instance to which you will eventually deploy in production. Otherwise, you will find your code has errors in production that don't occur in development, and it will be confusing and hard to debug.
You probably can't duplicate every aspect of your production environment, but if you can, make your development environment as close as possible.
To resolve the problem, make sure you choose a data type for your column that can hold the long data you send it.
- VARBINARY and BLOB holds up to 64KB
- MEDIUMBLOB holds up to 16MB
- LONGBLOB holds up to 4GB
Read https://dev.mysql.com/doc/refman/8.0/en/string-type-overview.html for more details.