我们都知道为了避免各方面的乱码,所以对各种能设置编码或可能潜伏的编码误期都进行校正。一开始在环境上下工夫的人,必将为未来节省很多无论是时间还是修复方面的成本。现在对mysql数据库进行部署。
我使用的wamp 集成包安装的。安装之后使用 SHOW VARIABLES LIKE 'char%' 或者 SHOW VARIABLES LIKE '%char%'
得到的结果是:
mysql> show variables like 'char%';
+-----------------------------+---------------------------------------------------------+
| Variable_name | Value
| +----------------------------+--------------------------------------------------------+
| character_set_client | gbk |
| character_set_connection | gbk |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | gbk |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | D:\wamp\bin\mysql\mysql5.5.8\share\charsets\ |
+--------------------------+----------------------------------------------------------+
8 rows in set (0.00 sec)
但是我想把它改成全部都是编码都是utf8的尝试和好多方法,使用defaulte-character-set =utf8,导致mysql无法启动
解决办法:
[mysqld]
经查询mysql 5.5.8里面使用的方法不再是default,而是
character-set-server = utf8
在mysqld下面加上这一条能修复以下两条
character_set_server为utf8
character_set_database为utf8
客户端需要再加上[client]
default-character-set = utf8
[mysql]字段里加入default-character-set=utf8 如下:
default-character-set=utf8
所以综上所述:【对应添加】
[client]
default-character-set = utf8
[mysqld]下面
character-set-server = utf8
[mysql]字段里加入default-character-set=utf8 如下:
default-character-set=utf8
大功告成,得到的结果为:
mysql> show variables like 'char%';
+-----------------------------+---------------------------------------------------------+
| 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:\wamp\bin\mysql\mysql5.5.8\share\charsets\ |
+--------------------------+----------------------------------------------------------+
8 rows in set (0.00 sec)