coolair
V2EX  ›  问与答

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

  •  
  •   coolair · Apr 1, 2017 · 2443 views
    This topic created in 3420 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
        1
    johnny23  
       Apr 1, 2017 via iPhone
    可以插米查
    SourceMan
        2
    SourceMan  
       Apr 1, 2017 via iPhone
    谁跟我一样觉得好污的吗??

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

    https://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html
    coolair
        5
    coolair  
    OP
       Apr 1, 2017
    @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
        6
    billlee  
       Apr 1, 2017
    你用的是 mysql-python 还是 mysqlclient?
    pymysql 的性能比 MySQLdb 差很多
    coolair
        7
    coolair  
    OP
       Apr 1, 2017 via Android
    @billlee 我用的 MySQL-python 这个库。
    billlee
        8
    billlee  
       Apr 3, 2017
    r#7 @coolair 你可以试试 mysqlclient, API 也是 MySQLdb. Mysql-python 都几年没更新了,我记得那个时候 mysql 都还没有 utf8mb4.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4136 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 05:33 · PVG 13:33 · LAX 22:33 · JFK 01:33
    ♥ Do have faith in what you're doing.