HiveBrain v1.2.0
Get Started
← Back to all entries
debugsqlMinor

unable to insert utf8mb4 characters in mysql 5.6

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
insertunablemysqlutf8mb4characters

Problem

recently i was facing problem in inserting emoji and other 4 bytes character in my mysql database then i found that my mysql version was 5.1 and it does not support utf8mb4 so i upgraded to mysql 5.6 which supports utf8mb4 and in my collation i have the option to select utf8mb4.but when i try to insert directly in table row through phpmyadmin i am getting this error
refered this link also

http://dba.stackexchange.com/questions/59126/set-value-of-character-set-client-to-utf8mb4

 1 row affected.
      Warning: #1366 Incorrect string value: '\xF0\x9F\x9A\x8A k...' for column 'rajulp' at row 1


i googled and found that this is because the database is not supporting utf8mb4 characters and then i followed few tutorials in internet to update my.cnf file and restarted mysql server as well as server.

https://mathiasbynens.be/notes/mysql-utf8mb4


i tried almost all possible combination but again when i type this in sql it throws maximum as utf8 because of that i am unable to insert eboji and several 4 bytes character.

Punjab me 1Train k niche 100 Sardar aa gaye..


output of below command in mysql

SHOW VARIABLES LIKE 'char%'

  character_set_client  utf8
     character_set_connection   utf8
   character_set_database   utf8mb4
    character_set_filesystem    binary
    character_set_results   utf8
   character_set_server utf8mb4
  character_set_system  utf8
     character_sets_dir /usr/share/mysql/charsets/


please guide

Solution

I had the same problem with an Ubuntu installation of MySQL 5.6.23.

I had to edit /etc/mysql/my.conf and add these entries to these sections:

[client]
default-character-set=utf8mb4

[mysqld]
character-set-server = utf8mb4

[mysql]
default-character-set=utf8mb4

Then as root execute: service mysql restart

Both my webserver connections and my local (shell) mysql connections worked with utf8mb4.

INSERT INTO some_table_name
(some_index_id,value_to_be_utf8mb4)
VALUES (55, x'F09F9A8A');

select * from some_table_name;
| some_index_id | value_to_be_utf8mb4 |
| 55 | |
1 rows in set (0.00 sec)

The following are from a fresh command line instantiation of mysql:

mysql> show variables like "%coll%";
+----------------------+--------------------+
| Variable_name | Value |
+----------------------+--------------------+
| collation_connection | utf8mb4_general_ci |
| collation_database | utf8mb4_general_ci |
| collation_server | utf8mb4_general_ci |
+----------------------+--------------------+

mysql> show variables like "%char%";
+--------------------------+----------------------------+
| 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 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

As a final note, the "character_set_system" is always "utf8" according to the mysql 5.x specifications, so that is normal.

Context

StackExchange Database Administrators Q#89355, answer score: 5

Revisions (0)

No revisions yet.