当前位置:Gxlcms > mysql > mysql 修改编码失败怎么办

mysql 修改编码失败怎么办

时间:2021-07-01 10:21:17 帮助过:54人阅读

mysql修改编码失败的解决办法就是在连接url后加上代码“?useUnicode=true&characterEncoding=UTF-8”即可。

推荐:《mysql视频教程》

mysql 修改编码不成功解决办法

问题描述:

改为UTF8之后,重新进入mysql,它又自动改回latin1

有个方法很简单,在连接url后加上如下代码即可:

?useUnicode=true&characterEncoding=UTF-8

特别注意,两个属性之间一定要用&符号的转义符,且不能带空格,否则会报错。

例子如下 hibernate.cfg.xml配置文件:

<? xml version = '1.0' encoding = 'UTF-8' ?>
<!DOCTYPE hibernate-configuration PUBLIC
           "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
           "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
 
     <!-- Generated by MyEclipse Hibernate Tools.                   -->
< hibernate-configuration >
 
     < session-factory >
         < property name = "dialect" >
             org.hibernate.dialect.MySQLDialect
         </ property >
         < property name = "connection.url" >
             jdbc:mysql://localhost:3306/share?useUnicode=true&amp;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 修改数据库级

a. 临时更改:

mysql>SET GLOBAL character_set_database=utf8;

b. 永久更改:

改了服务器级就可以了

2.修改表级

mysql>ALTER TABLE table_name DEFAULT CHARSET utf8;

更改了后永久生效

3.修改列级

修改示例:

          mysql>alter 
table `products` change `products_model` `products_model` varchar( 20 ) 
         character set  utf8 collate utf8_general_ci null default null;

更改了后永久生效

4.更改连接字符集

a. 临时更改:

mysql> set names utf8;

b. 永久更改:

修改my.ini文件 (linux 为my.cnf)

从my.ini下手

     [client]
       default-character-set=utf8
       [mysql]
        default-character-set=utf8
        [mysqld]
       default-character-set=utf8

linux 下修改这里容易遇到问题,出错后请参考http://blog.csdn.net/zhongdajiajiao/article/details/51698845

以上就是mysql 修改编码失败怎么办的详细内容,更多请关注gxlcms其它相关文章!

人气教程排行