23

Hello I am here to discus one thing. I am building up a web service that makes a goal for inserting emoji data into database field. I am working with Node JS + Mysql. I set charset to UTF-8 or utf8mb4 but this is not solving my problem. some emoji are inserting perfect { :) }. but some of are converted into square or removed. Please help me where I am doing wrong thing?

1

1 Answer 1

88

please add charset : 'utf8mb4' in your mysql connection pool.

e.g.

var connection = mysql.createConnection({
    host : 'you_ip',
    user : 'user',
    password : 'password',
    database : 'db',
    charset : 'utf8mb4'
});

Original Post: https://www.koffeewithkode.com/emoji-are-not-inserting-in-database-node-js-mysql/

4
  • 2
    also restart your node server. Mar 29, 2016 at 10:14
  • keep doing coding.. :) Mar 29, 2016 at 10:15
  • 3
    you saved me dude!
    – silent
    Feb 14, 2019 at 10:13
  • 1
    Saved me as well! Can't believe this isn't default behaviour... Nov 14, 2022 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.