MySQL乱码的问题解决
2015-11-18 20:23
525 查看
1. 建立数据库用如下例子:
create database mydb default charset=utf8;
2. 创建表如下;
drop table if exists 't_table';
create table t_table (
userid bigint(20) not null comment '游戏玩家的Id'
username varchar(64) not null comment '国际名字',
primary key(userid)
)engine=innodb default charset=utf8 comment='测试表';
3. 程序链接的时候,注意首先 运行 set names utf8 或者设置链接属性如: mysql_options(pMysql, MYSQL_SET_CHARSET_NAME, 'utf8');
4.用链接客户端或者命令行,链接数据库查看测试结果
碰到的一种情况是, 数据库和数据表,按照如上的方式,存储数据, 包含中文,日语,韩语等,在Navicat 连接查询现实正常,中,日,韩,均显示正常。
而用windows下的命令行,set names utf8后,中日韩显示均是乱码,而用set names gbk; 中日显示正常,韩文乱码,而用Mysql Query Browser 显示中日文字正常,
韩语不显示。 结果就是用3种工具查看,都是设定的set names utf8; 有个终端显示正常,有的显示不正常, 说明数据库里存的数据没有问题, 而是工具收到数据后,
显示的问题。
5. 判断此类问题,注意使用
show variables like 'character_set_%'; 查看链接的字符集.
6.修改链接或者结果字符集:
设置其他的 “variable_name”的 value 也为utf8:
SET character_set_client = utf8;
SET character_set_connection = utf8;
SET character_set_results = utf8;
SET character_set_database=utf8;
SET character_set_server=utf8;
或者使用set names utf8;
create database mydb default charset=utf8;
2. 创建表如下;
drop table if exists 't_table';
create table t_table (
userid bigint(20) not null comment '游戏玩家的Id'
username varchar(64) not null comment '国际名字',
primary key(userid)
)engine=innodb default charset=utf8 comment='测试表';
3. 程序链接的时候,注意首先 运行 set names utf8 或者设置链接属性如: mysql_options(pMysql, MYSQL_SET_CHARSET_NAME, 'utf8');
4.用链接客户端或者命令行,链接数据库查看测试结果
碰到的一种情况是, 数据库和数据表,按照如上的方式,存储数据, 包含中文,日语,韩语等,在Navicat 连接查询现实正常,中,日,韩,均显示正常。
而用windows下的命令行,set names utf8后,中日韩显示均是乱码,而用set names gbk; 中日显示正常,韩文乱码,而用Mysql Query Browser 显示中日文字正常,
韩语不显示。 结果就是用3种工具查看,都是设定的set names utf8; 有个终端显示正常,有的显示不正常, 说明数据库里存的数据没有问题, 而是工具收到数据后,
显示的问题。
5. 判断此类问题,注意使用
show variables like 'character_set_%'; 查看链接的字符集.
6.修改链接或者结果字符集:
设置其他的 “variable_name”的 value 也为utf8:
SET character_set_client = utf8;
SET character_set_connection = utf8;
SET character_set_results = utf8;
SET character_set_database=utf8;
SET character_set_server=utf8;
或者使用set names utf8;
相关文章推荐
- MySQL索引及优化
- MySQL远程(IP)连接报错:Host 'IP地址' is not allowed to connect to this MySQL server
- Mysql学习笔记三, 数据类型的选择
- mysql 批量更新
- Ubuntu14.04下mysql导入frm,MYD,MYI文件的方法
- mysql 增量备份还原
- 探究mysql预编译
- mysql设置远程登录后连接不上
- 常用的mysql命令
- mysql中 的 ENGINE = innodb; 是什么意思?
- MySQL Proxy 实现 MySQL 读写分离提高并发负载
- mysql 错误1449
- mysql中处理大小写敏感问题
- MySQL开发规范
- #include<mysql.h>
- mysql用户权限基本操作
- MySQL中事务概念的简洁学习教程
- mysql安装(亲自安装过)
- MySQL上的一些操作
- MySQL中的唯一索引的简单学习教程