› MySQL 5.5 Community Server
› MySQL 5.6 Community Server
› Percona Configuration Wizard
› XtraBackup 搭建主从复制
Great Sites on MySQL
› Percona
› MySQL Performance Blog
› Severalnines
推荐管理工具
› Sequel Pro
› phpMyAdmin
推荐书目
› MySQL Cookbook
MySQL 相关项目
› MariaDB
› Drizzle
参考文档
› http://mysql-python.sourceforge.net/MySQLdb.html
laoyuan
V2EX  ›  MySQL

为什么 UTF-8 编码的 MySQL 数据库碰到一些罕见字还是会报错: Incorrect string value

  •  
  •   laoyuan ·
    laoyuan · Mar 5, 2015 · 4628 views
    This topic created in 4225 days ago, the information mentioned may be changed or developed.
    CREATE TABLE IF NOT EXISTS `testx` ( `author` varchar(10) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    INSERT INTO `testx` (author) VALUES ('顾铮𠀡');

    Incorrect string value: '\xF0\xA0\x80\xA1' for column 'author' at row 1

    𠀡这个字是用 PHP html_entity_decode 来的:
    $author = html_entity_decode('顾铮𠀡', ENT_QUOTES, 'UTF-8');

    环境:Mac OSX 10.10 + MySQL 5.6、ubuntu 10.04 + MySQL 5.5
    laoyuan
        1
    laoyuan  
    OP
       Mar 5, 2015
    最关键的是 怎么解决呢。。
    raofeng
        2
    raofeng  
       Mar 5, 2015
    ```sql
    CREATE TABLE IF NOT EXISTS `testx` ( `author` varchar(10) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
    INSERT INTO `testx` (author) VALUES ('顾铮𠀡');
    ```
    raofeng
        3
    raofeng  
       Mar 5, 2015   ❤️ 1
    用 utf8mb4
    laoyuan
        4
    laoyuan  
    OP
       Mar 5, 2015
    @raofeng 谢谢,我还纳闷呢,怎么冒出4个字节来,原来问题在这里
    laoyuan
        5
    laoyuan  
    OP
       Mar 5, 2015
    @raofeng 成功了,在php里连接数据库后加上 mysql_query("set names utf8mb4");
    命令行里看到这个字是问号 ?,不过echo 到页面上正常的。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1073 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 23:05 · PVG 07:05 · LAX 16:05 · JFK 19:05
    ♥ Do have faith in what you're doing.