Get the App
SLTechnology News&Howtos  ›  Database  › 

How to solve the problem that mysql failed to modify the code

Shulou Source: shulou.com Published: 2022-06-01 02:03:56 10月18日 Update

This article mainly introduces how to solve the problem of mysql modification coding failure, has a certain reference value, friends in need can refer to. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.

The solution to mysql's failure to modify the code is to add the code "? useUnicode=true&characterEncoding=UTF-8" after connecting to the url.

The solution to the unsuccessful modification of mysql code

Problem description:

After changing to UTF8, re-enter mysql, and it automatically changes back to latin1

A simple method is to add the following code after connecting to url:

? useUnicode=true&characterEncoding=UTF-8

In particular, the escape character of the & symbol must be used between the two attributes without spaces, otherwise an error will be reported.

An example is the 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&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 changes:

Mysql > SET GLOBAL character_set_database=utf8

b. Permanent change:

Just change the server level.

two。 Modify table level

Mysql > ALTER TABLE table_name DEFAULT CHARSET utf8

Take effect permanently after the change

3. Modify column level

Example of modification:

Mysql > alter table `products` change `products_ model``products_ model` varchar (20) character set utf8 collate utf8_general_ci null default null

Take effect permanently after the change

4. Change the connection character set

a. Temporary changes:

Mysql > set names utf8

b. Permanent change:

Modify my.ini file (linux to my.cnf)

Start with my.ini

[client] default-character-set=utf8 [mysql] default-character-set=utf8 [mysqld] default-character-set=utf8 thank you for reading this article carefully. I hope it will be helpful for everyone to share how to solve the problem of mysql coding failure. At the same time, I also hope you can support us, pay attention to the industry information channel, and find out if you encounter problems. Detailed solutions are waiting for you to learn!

Tags: Code problem permanent article code method file method add A. success between two value example content at the same time character character set that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Xiaomi MySQL OPPO Reno Linux