修改ubuntu下mysql默认编码
编辑/etc/mysql/my.cnf文件,相当于windows中的my.ini:
找到[client] 添加:
default-character-set = utf8 // 默认字符集为utf8
找到[mysqld] 添加:
# 默认字符集为utf8
default-character-set = utf8
# 设定连接mysql数据库时使用utf8编码,以让mysql数据库为utf8运行
init_connect = 'SET NAMES utf8'
修改好后,重新启动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 | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+