微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Ubuntu修改mysql默认编码的方法

修改MysqL配置文件,使数据库与服务器操作系统的字符集设置一致。

    vi /etc/my.cnf 设置(如果没有发现这个文件,就新建1个)

    [MysqLd]

    datadir=/var/lib/MysqL

    socket=/var/lib/MysqL/MysqL.sock

    default-character-set=utf8  (增加的关键一句,使得数据库缺省以utf8存储)

    当然,修改后,要重启数据库

   

    再次用MysqL -u root -p命令进入数据库系统,用SHOW VARIABLES LIKE ‘character_set_%’;命令查看到如下内容

+————————–+———————————————————————–+

| Variable_name            | Value                                                                 |

+————————–+———————————————————————–+

| character_set_client     | latin1                                                                |

| character_set_connection | latin1                                                                |

| character_set_database   | utf8                                                                  |

| character_set_filesystem | binary                                                                |

| character_set_results    | latin1                                                                |

| character_set_server     | utf8                                                                  |

| character_set_system     | utf8                                                                  |

| character_sets_dir       | /usr/local/MysqL-5.1.20-beta-linux-i686-glibc23/share/MysqL/charsets/ |

+————————–+———————————————————————–+

    发现关键项目已经用了utf8,但这样还不够,还要保证客户端也是用utf8的字符集来操作的

    登录的时候,要用以下命令:MysqL –default-character-set=utf8 -u root -p

  

    再次用SHOW VARIABLES LIKE ‘character_set_%’;命令查看,结果变成了:

+————————–+———————————————————————–+

| 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       | /usr/local/MysqL-5.1.20-beta-linux-i686-glibc23/share/MysqL/charsets/ |

+————————–+———————————————————————–+

    这样才能保证客户端所发命令都是基于utf8格式的,比如说建立数据库和表,认就会以utf8编码,而无须再次指定。

需要说明一下,如果在修改编码之前已经建好数据库,需要删掉原来,重新建立数据库

if ($ != jQuery) {

$ = jQuery.noConflict();

}

var isLogined = false;

var cb_blogId = 101950;

var cb_entryId = 2251661;

var cb_blogApp = “feichan”;

var cb_blogUserGuid = “2e3900f8-370f-e111-b422-842b2b196315”;

var cb_entryCreatedDate = ‘2011/11/16 20:02:00’;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐