Egg: mysql 保存 emoji 表情数据时出错

Created on 10 Jul 2018  ·  3Comments  ·  Source: eggjs/egg

先来看个报错信息:
1
2

执行 insert sql语句的时候由于username字段保存的数据包含emoji的表情(那个狗头),导致保存失败。查阅了很多资料,都说是数据库的字符集问题,数据库及数据表的字符及字符集已经从原来的utf8utf8_general_ci改为utf8mb4/utf8mb4_general_ci

不知道为什么还是不行,请问下这种问题有解决方案吗?有想过在保存之前用base64转码,解析的时候再解码,但觉得这样处理很麻烦,很不优雅。

Most helpful comment

mysql 连接的字符集charset 设对了吗?

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

All 3 comments

Translation of this issue:


mysql Error saving emoji emoticon data

First look at an error message:
1
2

When the insert sql statement is executed, the data saved in the username field contains the emoji expression (the dog head), which causes the save to fail. Checked a lot of information, said that the character set of the database, the database and data table characters and character sets have been changed from the original utf8utf8_general_ci to utf8mb4/utf8mb4_general_ci

I don't know why it still doesn't work. Is there a solution to this problem? I have thought about transcoding with base64 before saving, and decoding when parsing, but I feel that this is very troublesome and not very elegant.

mysql 连接的字符集charset 设对了吗?

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

@BaffinLee 果然解决了,谢谢

Was this page helpful?
0 / 5 - 0 ratings