标签 字符集 下的文章

在mysql中查看字符集:

show variables like ‘%char%’;

如果database和server都不是utf8,则需要配置mysql的配置文件。

在  /etc/mysql/my.cnf  中,[mysqld]的配置下,添加:

character_set_server=utf8
init_connect='SET NAMES utf8'

重启mysql即可

在创建database时:

CREATE DATABASE IF NOT EXISTS xxxx DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

在java中连接mysql时这样设置:

datasources.url=jdbc:mysql://192.168.1.1:3306/xxxx?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull