coolair
V2EX  ›  问与答

“𥻗”这种字,插入 MySQL 数据库,插不进去,插进去以后显示??怎么处理?

  •  
  •   coolair · Apr 1, 2017 · 2575 views
    This topic created in 3520 days ago, the information mentioned may be changed or developed.
    Supplement 1  ·  Apr 1, 2017
    大家不要用 MySQLdb 这个库,用 pymysql 解决所有问题。
    8 replies  •  2017-04-03 12:19:43 +08:00
    johnny23
    johnny23
    Apr 1, 2017 via iPhone
    1
    可以插米查
    SourceMan
    SourceMan
    Apr 1, 2017 via iPhone
    2
    谁跟我一样觉得好污的吗??

    楼主可以看下是不是需要跟存储 emoji 一样用其它编码格式
    mN71eOOprFyMsnPx
    mN71eOOprFyMsnPx
    Apr 1, 2017
    3
    确认表或数据库使用的编码是 utf-8 。
    使用 utf-8 编码,是不会有这种问题的。
    raptium
    raptium
    Apr 1, 2017
    4
    utf8mb4 应该可以,𥻗 用 UTF-8 编码需要 4 个字节, MySQL 普通的 utf8 只支持最多 3 个字节

    https://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html
    coolair
    coolair
    OP
    Apr 1, 2017
    5
    @johnny23
    @SourceMan
    @FifiLyu
    @raptium 我是用的 utf8mb4 ,刚刚测试了下,直接用 phpmyadmin 可以插入,但是用 DataGrip 和用 Python 的 MySQLdb 插入的时候,却报错:
    [HY000][1366] Incorrect string value: '\xF0\xA5\xBB\x97\xF0\xA5...' for column 'name' at row 1
    billlee
    billlee
    Apr 1, 2017
    6
    你用的是 mysql-python 还是 mysqlclient?
    pymysql 的性能比 MySQLdb 差很多
    coolair
    coolair
    OP
    Apr 1, 2017 via Android
    7
    @billlee 我用的 MySQL-python 这个库。
    billlee
    billlee
    Apr 3, 2017
    8
    r#7 @coolair 你可以试试 mysqlclient, API 也是 MySQLdb. Mysql-python 都几年没更新了,我记得那个时候 mysql 都还没有 utf8mb4.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2340 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 03:07 · PVG 11:07 · LAX 19:07 · JFK 22:07
    ♥ Do have faith in what you're doing.