mysql Emoji表情字符集轉換

<pre name="code" class="html">Java代碼  
java.sql.SQLException: Incorrect string value: '\xF0\x9F\x92\x94' for column 'name' at row 1  
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)  
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3593)  
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3525)  
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1986)  
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2140)  
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2620)  
    at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1662)  
    at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1581)  

1. 修改my.cnf
[mysqld]
character-set-server=utf8mb4
[mysql]  
default-character-set=utf8mb4
修改後重啓Mysql
 

 
3. 將已經建好的表也轉換成utf8mb4
ALTER TABLE UserInfo  CHARSET=utf8mb4;

命令:alter table TABLE_NAME convert to character set utf8mb4 collate utf8mb4_bin; (將TABLE_NAME替換成你的表名)
相關文章
相關標籤/搜索