Mysql – Trying to support unicode in MySQL database

character-setMySQL

I am doing a project in which I have to save tweets into my MySQL database. The problem is some tweets contains smilies and other symbols which I am not able to save – it shows error like below:

Incorrect string value: '\xF0\x9F\x98\x82. …' for column 'text' at row 1

I was trying to convert to utf8mb4 using this link tutorial, and in step 5, I have changed my.ini file in my C:\ProgramData\MySQL\MySQL Server 5.6 directory. But when I do

SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%'; 

in my MySQL console, I am not getting the desired result, meaning my character set is not changed to utf8mb4 – it is still utf8.

Please guide me how to resolve this, as I am new to this. I have attached an image to the step 5 (Modify connection, client, and server character sets) of the above tutorial.enter image description here

Best Answer

You need utf8mb4 instead of utf8 to get ? and a number of other emoji.

You need SET NAMES utf8mb4 after connecting.

You also need to make sure SHOW CREATE TABLE says utf8mb4.

Your "this link tutorial" seems to be broken. I would like to see what is says. (And perhaps find an error in it.)

More discussion of utf8mb4.