Home >Database >Mysql Tutorial >Mysql插入乱码问题_MySQL

Mysql插入乱码问题_MySQL

WBOY
WBOYOriginal
2016-06-01 13:02:49904browse

原因:

数据库table和插入语句的字符编码不匹配或者数据库table的编码不支持中文

解决方案:

修改table中的字符编码为:utf-8(或gbk,gb2312)

在代码中链接数据库时,连接字符串后面加上?characterEncoding=utf8,例如jdbc:mysql://localhost:3306/db_zhu?characterEncoding=utf8

在出现插入或修改出现乱码时,首先在mysql终端执行下插入语句,检查是否插入正确。然后再代码中打印下插入语句,看是否有乱码或问号?。最看看连接字符串是否设置了characterEncoding

附:

wamp执行mysql终端时需要mysql -u root 才能有有root权限。

拓展:

http://www.cnblogs.com/hongfei/archive/2011/12/29/set-names-utf8.html

Statement:
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