本文主要是介绍只要三步,完全解决数据库中文乱码问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
前几天安装MySQL的时候,发现根本没法输入中文,都是乱码,然后在网上查了找了很多文章,整理一下,留作笔记.
1. 修改my.ini
在 D:\MySQL\MySQL Server 5.5\my.ini文件中,找到# CLIENT SECTION下面的[mysql],做如下修改
default-character-set=utf8, 具体如下
# CLIENT SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by MySQL client applications.
# Note that only client applications shipped by MySQL are guaranteed
# to read this section. If you want your own MySQL client program to
# honor these values, you need to specify it as an option during the
# MySQL client library initialization.
#
[client]
port=3306
[mysql]
default-character-set=utf8
# SERVER SECTION
2.修改好以后,再次查看编码格式,你会发现仍旧有一个latin1:
| character_set_server
下面,找到 D:\Program Files\MySQL\MySQL Server 5.5\bin\MySQLInstanceConfig.exe
重新配置数据库编码格式为utf8.
3. 到这一步的时候,再次查看编码格式,你会发现你的编码格式如下:
mysql> SHOW VARIABLES LIKE 'character%';
+--------------------------+---------------------------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | D:\Program Files\MySQL\MySQL Server 5.0\share\charsets\ |
+--------------------------+---------------------------------------------------------+
理论上讲,编码格式应该是设置成功了的,但是在Windows系统下,试图通过
MySQL Command Line Client进行insert操作肿么还是乱码呢? 原来是MySQL Command Line Client出了幺蛾子
!因为它的显示有问题
好吧,给一个简单到哭的指令:
set names gbk;
果然很简单,但是效果是立竿见影,瞬间所有的问题都解决了.
附1:理想编码格式:
mysql> show variables like '%char%';
+--------------------------+---------------------------------------------------------+
| Variable_name | Value |
+--------------------------+---------------------------------------------------------+
| character_set_client | gbk |
| character_set_connection | gbk |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | gbk |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | D:\Program Files\MySQL\MySQL Server 5.5\share\charsets\ |
+--------------------------+---------------------------------------------------------+
8 rows in set (0.00 sec)
这篇关于只要三步,完全解决数据库中文乱码问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!