How to store Emoji Character in My SQL Database

2019-01-01 03:25发布

问题:

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

回答1:

1) Database: Change Database default collation as utf8mb4.

2) Table: Change table collation as CHARACTER SET utf8mb4 COLLATE utf8mb4_bin.

Query:

ALTER TABLE Tablename CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin

3) Code:

INSERT INTO tablename (column1, column2, column3, column4, column5, column6, column7)
VALUES (\'273\', \'3\', \'Hdhdhdh              
                            
标签: mysql