mysql 中文乱码的解决办法

I would not suggest Richies answer, because you are screwing up the data inside the database. You would not fix your problem but try to "hide" it and not being able to perform essential database operations with the crapped data.

If you encounter this error either the data you are sending is not UTF-8 encoded, or your connection is not UTF-8. First, verify, that the data source (a file, ...) really is UTF-8.

Then, check your database connection, you should do this after connecting:

SET NAMES ‘utf8‘;
SET CHARACTER SET utf8;

Next, verify that the tables where the data is stored have the utf8 character set:

SELECT
  `tables`.`TABLE_NAME`,
  `collations`.`character_set_name`
FROM
  `information_schema`.`TABLES` AS `tables`,
  `information_schema`.`COLLATION_CHARACTER_SET_APPLICABILITY` AS `collations`
WHERE
  `tables`.`table_schema` = DATABASE()
  AND `collations`.`collation_name` = `tables`.`table_collation`
;

Last, check your database settings:

mysql> show variables like ‘%colla%‘;
mysql> show variables like ‘%charac%‘;

If source, transport and destination are UTF-8, your problem is gone;)

另外,安装完mysql之后,应该运行一下命令来设置编码为utf-8:

先在命令行运行:status查看编码是不是utf8。

set character_set_server = ‘utf8‘;

set character_set_connection = ‘utf8‘;

set character_set_results = ‘utf8‘;

set character_set_client = ‘utf8‘;

改变database的编码可以用:   alter database db_name default character set ‘utf8‘;

show create table t1;  可以查看表的schema

时间: 2024-08-03 01:39:55

mysql 中文乱码的解决办法的相关文章

详解get请求和post请求参数中文乱码的解决办法

首先出现中文乱码的原因是tomcat默认的编码方式是"ISO-8859-1",这种编码方式以单个字节作为一个字符,而汉字是以两个字节表示一个字符的. 一,get请求参数中文乱码的解决办法 对于get请求解决中文乱码有两种途径一种是修改tomcat默认的编码方式为"UTF-8" 在tomcat的server.xml里把 <Connector connectionTimeout="50000" port="8080" pro

C#中WebClient中文乱码的解决办法

原文:C#中WebClient中文乱码的解决办法 第一次尝试: string question = textBox1.Text.ToString(); WebClient youdao = new WebClient(); youdao.Encoding = System.Text.Encoding.GetEncoding("GB2312"); Uri uri = new Uri("http://xxxxxxxxxxxxxx"); textBox1.Text =yo

resin后台输出中文乱码的解决办法!

最近从tomcat移植到resin,发现这东西不错啊! 只是后台输出时有时候中文会乱码. 现在找到resin后台输出中文乱码的解决办法: 编辑conf/resin.con文件: <!--javac compiler="internal" args="-source 1.5"/--> 修改成这样: <javac compiler="javac" args="-encoding utf-8"/> 重启服务器

sae python中Mysql中文乱码的解决

一开始我用的是: db=MySQLdb.connect(db=sae.const.MYSQL_DB,user=sae.const.MYSQL_USER,passwd=sae.const.MYSQL_PASS,host=sae.const.MYSQL_HOST,port=int(sae.const.MYSQL_PORT)) 数据库编码与python代码的编码都已设为utf8,在PHPMyAdmin中添加中文记录,在网页查询显示中却显示乱码,我在网上各种搜索都找不到解决方法.最后终于发现在连接数据库

get请求和post请求参数中文乱码的解决办法

get请求参数中文乱码的解决办法 在tomcat的server.xml里的Connector加个URIEncoding="UTF-8",把 <Connector connectionTimeout="50000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/> 改为 <Connector connectionTimeout=&qu

Android 关于HttpClient上传中文乱码的解决办法

使用过HttpClient的人都知道可以通过addTextBody方法来添加要上传的文本信息,但是,如果要上传中文的话,或还有中文名称的文件会出现乱码的问题,解决办法其实很简单: 第一步:设置MultipartEntityBuilder的编码方式为UTF-8. builder.setCharset(Charset.forName(HTTP.UTF_8));//设置请求的编码格式 第二步:创建ContentType对象,指定UTF-8编码. ContentType contentType= Con

[MAC Eclipse] Eclipse for MAC 中文乱码的解决办法

笔者将在windows下的eclipse写的代码拷贝到MAC下,发现中文会出现乱码. 最初笔者遇到这个问题的时候,在网络上寻找了解决办法,出来的第一个网页(http://blog.csdn.net/woaifen3344/article/details/45023351),发现解决无效. 后来尝试得到其它办法.如下. 再回到页面,转换成功. 链接地址:http://www.ithao123.cn/content-9725229.html

关于HttpClient上传中文乱码的解决办法

使用过HttpClient的人都知道可以通过addTextBody方法来添加要上传的文本信息,但是,如果要上传中文的话,或还有中文名称的文件会出现乱码的问题,解决办法其实很简单: 第一步:设置MultipartEntityBuilder的编码方式为UTF-8. builder.setCharset(Charset.forName(HTTP.UTF_8));//设置请求的编码格式 第二步:创建ContentType对象,指定UTF-8编码. ContentType contentType= Con

CentOS中文乱码之解决办法

在学习Linux的过程中,最先碰到的是通过SSH终端连接时发现有乱码出现,使用这篇文章先从这里说起. 在 ssh , telnet 终端中文显示乱码解决办法#vim /etc/sysconfig/i18n 将原内容:LANG="en_US.UTF-8" SYSFONT="latarcyrheb-sun16" 修改为: LANG="zh_CN.GB18030" LANGUAGE="zh_CN.GB18030:zh_CN.GB2312:zh