Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report