用户工具


1、查看msyql字符集

show variables like 'char%';

2、sudo vim /etc/my.cnf,加上如下配置

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
default-character-set=utf8  # 加上这句话
default-character=utf8      # 加上这句话


[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[client]                    # 加上这句话
default-character-set=utf8  # 加上这句话

3、重启mysql

sudo service mysqld restart

4、创建数据库,指定utf-8 编码格式

CREATE DATABASE myweb default charset utf8 COLLATE utf8_general_ci;

5、创建表,指定utf-8 编码格式

USE myweb;
CREATE TABLE class
(
   class_id BIGINT NOT NULL COMMENT  '班级id',
   class_name VARCHAR(256) NOT NULL COMMENT '班级名称',
   class_master VARCHAR(256) NOT NULL COMMENT '班主任',
   PRIMARY KEY (class_id)
)ENGINE =InnoDB DEFAULT CHARSET=utf8 COMMENT ='班级表';

6、java-mysql连接设置成utf8

jdbc:mysql://master:3306/myweb?useUnicode=true&characterEncoding=utf8

7、设置html页面

<head>
    <title>Hello World</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>

8、设置rest方式返回的json编码

@RequestMapping(value = "/getStudentInfo", method = RequestMethod.GET, produces = "application/json; charset=utf-8")