Home >Database >Mysql Tutorial >What should I do if mysql fails to modify the encoding?

What should I do if mysql fails to modify the encoding?

藏色散人
藏色散人Original
2020-11-02 09:16:391889browse

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.

What should I do if mysql fails to modify the encoding?

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:



 
     
< hibernate-configuration >
 
     < session-factory >
         < property name = "dialect" >
             org.hibernate.dialect.MySQLDialect
         
         < property name = "connection.url" >
             jdbc:mysql://localhost:3306/share?useUnicode=true&amp;characterEncoding=UTF-8
         
         < property name = "connection.username" >root
         < property name = "connection.password" >accp
         < property name = "connection.driver_class" >
             com.mysql.jdbc.Driver
         
         < property name = "myeclipse.connection.profile" >ssh
         < property name = "show_sql" >true
         < property name = "format_sql" >true
         < 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" />
     

============================ ======

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn