I am using Emoji character in my project. That characters are saved (??) into mysql database. I had used database Default collation in utf8mb4_general_ci
.
It show
1366 Incorrect string value: '\xF0\x9F\x98\x83\xF0\x9F...' for column 'comment' at row 1
step 1, change your database's default charset:
step 2, set charset when creating table:
or alter table
If you are using Solr + Mysql + Java, you can use:
This can be Used :
In above case this is one of the solutions to store your emoticons in your system.
Steps to use it:
Library used: import java.net.URLDecoder; import java.net.URLEncoder;
Code example:
The command to modify the column is:
And we need to use type =
BLOB
Example to modify is as under:-
I checked that latest mySQL and other databases don't need
''
to use in command on table_name, column_name etc.Fetch and Save data: Directly save the chat content to column and to retrieve data, fetch data as byte array
(byte[])
from db column and then convert it tostring
e.g. (Java code)1) Database: Change Database default collation as
utf8mb4
.2) Table: Change table collation as
CHARACTER SET utf8mb4 COLLATE utf8mb4_bin
.Query:
3) Code:
I have updated my database and table to upgraded from utf8 to utf8mb4. But nothing works for me. Then I tried to update column datatype to blob, luckily it worked for me and data has been saved. Even my database and table both are CHARACTER SET utf8 COLLATE utf8_unicode
My answer only adds to Selvamani P answer.
You might also need to change any
SET NAMES utf8
queries withSET NAMES utf8mb4
. That did the trick for me.Also, this is a great article to port your website from utf8 to utf8mb4. In particular the article makes 2 good points on indexes and repairing tables after converting them to utf8mb4:
INDEXES
REPAIRING TABLES
Read more about the queries to repair tables on the article.