我的mysql位于云计算平台,每次将
haracter_set_client;
character_set_connection;
character_set_database;
character_set_results;
character_set_server;
改为UTF8之后,重新进入mysql,它又自动改回latin1
而且我每次进入mysql是不需要密码的,直接输入mysql就可以进入
从my.ini下手
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
default-character-set=utf8
以上3个section都要加default-character-set=utf8,平时我们可能只加了mysqld一项。
然后重启mysql,执行
mysql> SHOW VARIABLES LIKE 'character%';
mysql> SHOW VARIABLES LIKE 'collation_%';
确保所有的Value项都是utf8即可。
如果我没有权限修改my.ini呢?
还有其他的办法吗?
@kcher:
有个方法很简单,在连接url后加上如下代码即可:
特别注意,两个属性之间一定要用&符号的转义符,且不能带空格,否则会报错。
例子如下 hibernate.cfg.xml配置文件:
<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" <!-- Generated by MyEclipse Hibernate Tools. --><hibernate-configuration> <session-factory> <property name="dialect"> org.hibernate.dialect.MySQLDialect </property> <property name="connection.url"> </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>数据库属性中可以单独设置
能否回答详细点,
character_set_client;
character_set_connection;
character_set_results;
这些属性能在数据库中单独设置?
多打一条命令
set names utf8;
MySQL文档中说:
set names 与
character_set_client;
character_set_connection;
character_set_results;
这三个属性的单独设置效果一样的