日期:2014-05-16  浏览次数:20775 次

ubuntu修改mysql默认编码
1、$ sudo cp /etc/mysql/my.cnf /etc/mysql/my.cnf_backup_2010-8-23 # 备份mysql的配置文件 2、$ sudo gedit /etc/mysql/my.cnf [mysql] # Set the default character set UTF-8: default-character-set=utf8 [client] # Set the default character set UTF-8: default-character-set=utf8 [mysqld] # Set the default character set UTF-8: default-character-set=utf8 init_connect='SET NAMES utf8' 3、$ sudo /etc/init.d/mysql restart # 重启mysql服务 4、mysql -u root -p Enter password: ****** > \s # 查看是否配置成功 Client characterset: utf8 Server characterset: utf8 >quit 5、修改完以后,用jdbc时,url为:jdbc:mysql://localhost:3306/tyepc?useUnicode=true&characterEncoding=GBK&autoReconnect=true就可以插入中文了。查询也没问题 如果encoding为utf8还是不能插入中文,除非用GBK,不是很理解。有知道的朋友告一声!