Home > Database > Mysql Tutorial > Mysql5 字符集编码问题解决_MySQL

Mysql5 字符集编码问题解决_MySQL

WBOY
Release: 2016-06-01 13:19:47
Original
1092 people have browsed it

bitsCN.com 我们遵循的标准是,数据库,表,字段和页面或文本的编码要统一起来
很多mysql数据库工具(除了phpmyadmin,我偶尔用,功能强速度慢)都不支持创建时指定数据库编码,当然可以改my.ini来解决这个问题,但是需要重新启动mysql,不过用下面的语句会更有效
GBK: create database test2 DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;
UTF8: CREATE DATABASE `test2` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
注意:如果不是通过my.ini配置文件设置的内容,只在当前状态下有效,当重启数据库服务后失效。所以如果想要不出现乱码只有修改my.ini文件,数据库编码可以在创建数据库时候指定UTF8,如下:
|character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8
注意该配置| character_set_server | latin1 无法设置成UTF8
交互时候仍然会出现乱码。
只有当修改my.ini中设置UTF8,才会全部修改成UTF8
-------------------------
mysql设置编码命令
SET character_set_client = utf8;
SET character_set_connection = utf8;
SET character_set_database = utf8;
SET character_set_results = utf8;/*这里要注意很有用*/
SET character_set_server = utf8;
SET collation_connection = utf8_bin;
SET collation_database = utf8_bin;
SET collation_server = utf8_bin;
my.ini中配置默认编码
default-character-set=utf8
连接数据库设置编码
jdbc:mysql://192.168.0.5:3306/test?characterEncoding=utf8
/*****************************************java与mysq编码对应****************************************/
java中的常用编码UTF-8;GBK;GB2312;ISO-8859-1;
对应mysql数据库中的编码utf8;gbk;gb2312;latin1

---------------------------
数据库连接串中指定字符集URL=jdbc:mysql://yourIP/college?user=root&password=yourPassword&useUnicode=true&characterEncoding=gbk

不要试图通过sql命令来修改character_set_server,那是临时的,还是老老实实修改my.ini或者linux下的my.cnf

[mysqld]
......
character_set_server=utf8
default-character-set=utf8
bitsCN.com

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template