집 >데이터 베이스 >MySQL 튜토리얼 >tomcat 中文乱码, mysql 中文乱码_MySQL
Tomcat
修改server.xml中的
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding='UTF-8' />
另外HttpURLConnection上传参数的时候要转码成url编码
outStream.writeBytes("&" + URLEncoder.encode(key, "utf-8") + "=" + URLEncoder.encode(value, "utf-8"));
修改 my.cnf ,在 [mysqld] 下面添加
character-set-server = utf8
创建数据库的时候制定编码格式为 utf-8
CREATE DATABASE dbname DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
或者修改已有数据库/表编码格式为 utf-8
ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_unicode_ci;ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;