Reputation: 107
So, today i was faced with the problem:
SQL request:
INSERT INTO `sample` (`lol`) VALUES ('👈');
Response:
Error Code: 1366. Incorrect string value: '\xF0\x9F\x91\x88' for column 'lol' at row 1
Collation:
mysql> SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
+--------------------------+--------------------+
| Variable_name | Value |
+--------------------------+--------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| collation_connection | utf8mb4_unicode_ci |
| collation_database | utf8mb4_unicode_ci |
| collation_server | utf8mb4_unicode_ci |
+--------------------------+--------------------+
10 rows in set, 1 warning (0.00 sec)
my.ini:
[client]
port=3306
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
collation-server = utf8mb4_unicode_ci
character-set-server=utf8mb4
How to fix it?
Upvotes: 1
Views: 802
Reputation: 107
The solution was simple. You just need to do
SET NAMES 'utf8mb4'
Upvotes: 1