And the QQ said there are many Martian and emoji expression pictures, these data, if directly insert to MySQL database, general will error, set to UTF8 are not good, must be changed to UTF8MB4 code, the difference between the two see: MySQL utf8mb4 and emoji expression , most of the online solution is to modify the MY.CNF parameters, set the MySQL encoding for UTF8MB4, although this method is thorough, but usually to restart MySQL, will cause the production system temporary machine.
The following are the less-affected processing methods:
Premise: MySQL version can not be too low, less than 5.5.3 version does not support UTF8MB4 encoding.
The corresponding field in the table, such as the name field of the membership table, whose character set is modified to UTF8MB4.
Then in the Java client, upgrade Mysql-connector-java to the latest version (currently the latest version is 5.1.37), and finally modify the configuration of the Druid data source, add a line:
<name= "Connectioninitsqls" value= "Set names utf8mb4;" />
Complete configuration reference below:
<BeanID= "DataSource"class= "Com.alibaba.druid.pool.DruidDataSource"Init-method= "Init"Destroy-method= "Close"> < Propertyname= "Driverclassname"value= "${jdbc-driver}"/> < Propertyname= "url"value= "${jdbc-url}"/> < Propertyname= "username"value= "${jdbc-user}"/> < Propertyname= "Password"value= "${jdbc-password}"/> < Propertyname= "Filters"value= "Stat"/> < Propertyname= "Maxactive"value= " the"/> < Propertyname= "InitialSize"value= "1"/> < Propertyname= "Maxwait"value= "60000"/> < Propertyname= "Minidle"value= "1"/> < Propertyname= "Timebetweenevictionrunsmillis"value= " the"/> < Propertyname= "Minevictableidletimemillis"value= "300000"/> < Propertyname= "Validationquery"value= "Select ' X '"/> < Propertyname= "Testwhileidle"value= "true"/> < Propertyname= "Testonborrow"value= "false"/> < Propertyname= "Testonreturn"value= "false"/> < Propertyname= "Poolpreparedstatements"value= "true"/> < Propertyname= "Maxpoolpreparedstatementperconnectionsize"value= " the"/> < Propertyname= "Connectioninitsqls"value= "Set names utf8mb4;"/> </Bean>
Basically should be OK, if not yet, check the JDBC connection string settings:
jdbc:mysql://localhost:3306/db name? Useunicode=true&characterencoding=utf8
If it doesn't work, remove the last Useunicode=true&characterencoding=utf8.
MYSQL:UTF8MB4 's Problem