The solution to the failure of mysql to modify the encoding is to add the code "?useUnicode=true&characterEncoding=UTF-8" after the connection url.
Recommended: "mysql video tutorial"
mysql solution to unsuccessful encoding modification
Problem description:
After changing to UTF8, re-enter mysql, and it will automatically change back to latin1
There is a very simple method, add the following code after connecting to the url That’s it:
?useUnicode=true&characterEncoding=UTF-8
Special attention must be paid to the ampersand escape character between the two attributes, and no spaces, otherwise an error will be reported.
The example is as follows hibernate.cfg.xml configuration file:
xml version = '1.0' encoding = 'UTF-8' ?> < hibernate-configuration > < session-factory > < property name = "dialect" > org.hibernate.dialect.MySQLDialect property > < property name = "connection.url" > jdbc:mysql://localhost:3306/share?useUnicode=true&characterEncoding=UTF-8 property > < property name = "connection.username" >root property > < property name = "connection.password" >accp property > < property name = "connection.driver_class" > com.mysql.jdbc.Driver property > < property name = "myeclipse.connection.profile" >ssh property > < property name = "show_sql" >true property > < property name = "format_sql" >true property > < mapping resource = "cn/lihuoqing/po/ShUser.hbm.xml" /> < mapping resource = "cn/lihuoqing/po/ShOptions.hbm.xml" /> < mapping resource = "cn/lihuoqing/po/ShFiles.hbm.xml" /> < mapping resource = "cn/lihuoqing/po/ShComments.hbm.xml" /> < mapping resource = "cn/lihuoqing/po/ShDown.hbm.xml" /> session-factory > hibernate-configuration >
============================ ======
1 Modify the database level
a. Temporary change:
mysql>SET GLOBAL character_set_database=utf8;
b. Permanent Change:
Just change the server level
2. Modify the table level
mysql>ALTER TABLE table_name DEFAULT CHARSET utf8;
The changes will take effect permanently
3. Modify the column level
Modification Example:
mysql>alter table `products` change `products_model` `products_model` varchar( 20 ) character set utf8 collate utf8_general_ci null default null;
After changing the permanent effect
4. Change the connection character set
A. ; set names utf8;
b. Permanent changes:
Modify the my.ini file (my.cnf for Linux)
Start with my.ini
[client] default-character-set=utf8 [mysql] default-character-set=utf8 [mysqld] default-character-set=utf8
It is easy to encounter problems when modifying this under Linux. If you make an error, please refer to http://blog.csdn.net/zhongdajiajiao/article/details/51698845
The above is the detailed content of What should I do if mysql fails to modify the encoding?. For more information, please follow other related articles on the PHP Chinese website!