下载好.zip文件安装好之后,默认的数据库格式不是utf8,运行mysql命令,之后运行mysql->show variables like '%char%';出现下面这样的:
这就是导致jsp页面utf8编码但是中文到数据库就是乱码的原因。
需要mysql根目录下复制my-default.ini到本目录my.ini,之后再里面增加下面的红色字体内容:
[mysql]
default-character-set=utf8
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# 设置mysql的安装目录
basedir = D:/tools/mysql/mysql-5.6.11-winx64
# 设置mysql数据库的数据存放目录
datadir = D:/tools/mysql/mysql-5.6.11-winx64/data
# port = .....
# server_id = .....
character-set-server=utf8
全部都是utf8了,之后jsp就可以正常提交中文到mysql也能正常显示了。