Ubuntu下mysql修改字符集为utf8

首先停止mysql服务:

sudo /etc/init.d/mysql stop

修改mysql的配置文件:

sudo gedit /etc/mysql/my.cnf

找到客户端配置[client] 在下面添加

#默认字符集为utf8
default-character-set=utf8

找到[mysqld] 添加

#默认字符集为utf8
character_set_server=utf8
#default-character-set=utf8 
#说明如果这样设置启动会出错,所以用character_set_server=utf8代替default-character-set=utf8

找到[mysql] 添加

#默认字符集为utf8
default-character-set=utf8

重启mysql服务

sudo /etc/init.d/mysql start

进入mysql的命令行

mysql -uusername -puserpassword

查看编码是否改变

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       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
说明编码修改成功!


Ubuntu下mysql修改字符集为utf8

上一篇:Oracle之sql语句优化


下一篇:MYSQL