Mysql – DatabaseError: 1366 (HY000): Incorrect string value: ‘\xF0\x9F\x92\x96’

MySQL

I'm using MySQL 5.7.20. My schema, tables and columns are all supporting utf8mb4. I used the following:

ALTER SCHEMA `MyDB`  DEFAULT CHARACTER SET utf8mb4  DEFAULT COLLATE utf8mb4_general_ci ;
ALTER TABLE MyDB.Videos CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

I don't understand why I'm still getting the following error:

DatabaseError: 1366 (HY000): Incorrect string value: '\xF0\x9F\x92\x96' for column 'Content' at row 1

I can't figure out the reason, please help.

Best Answer

When I specified CHARSET='UTF8MB4'in my connection parameters, it worked.