首页 > 代码库 > Linux下MySQL5.6的修改字符集编码为UTF8
Linux下MySQL5.6的修改字符集编码为UTF8
一、登录MySQL查看用SHOW VARIABLES LIKE ‘character%’;下字符集,显示如下:
+--------------------------+----------------------------+| Variable_name | Value |+--------------------------+----------------------------+| character_set_client | utf8 || character_set_connection | utf8 || character_set_database | latin1 || character_set_filesystem | binary || character_set_results | utf8 || character_set_server | latin1 || character_set_system | utf8 || character_sets_dir | /usr/share/mysql/charsets/ |+--------------------------+----------------------------+
character_set_database和character_set_server的默认字符集还是latin1。
二、最简单的完美修改方法,修改mysql的my.cnf文件中的字符集键值(注意配置的字段细节):
1、在[client]字段里加入default-character-set=utf8,如下: [client]port = 3306socket = /var/lib/mysql/mysql.sockdefault-character-set=utf8 2、在[mysqld]字段里加入character-set-server=utf8,如下: [mysqld]port = 3306socket = /var/lib/mysql/mysql.sockcharacter-set-server=utf8 3、在[mysql]字段里加入default-character-set=utf8,如下: [mysql]#no-auto-rehashdefault-character-set=utf8
修改完成后,service mysql restart重启mysql服务就生效。注意:[mysqld]字段与[mysql]字段是有区别的。
重启mysql服务。
sudo service mysql start
使用SHOW VARIABLES LIKE ‘character%’;查看,发现数据库编码全已改成utf8。
+--------------------------+----------------------------+| 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/share/mysql/charsets/ |+--------------------------+----------------------------+
Linux下MySQL5.6的修改字符集编码为UTF8
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。