mysql 修改编码不成功解决办法
问题描述:
改为utf8之后,重新进入mysql,它又自动改回latin1
有个方法很简单,在连接url后加上如下代码即可:
?useunicode=true&characterencoding=utf-8
特别注意,两个属性之间一定要用&符号的转义符,且不能带空格,否则会报错。
例子如下 hibernate.cfg.xml配置文件:
< 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 修改数据库级
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