在/etc/my.cnf文件中,添加两行内容:
[client]
default-character-set=utf8
[mysqld]
default-character-set=utf8
注意:这个文件不一定存在,需要将安装目录下 /MYSQL_HOME/support-files/my-medium.cnf 复制到/etc/下,重命名
修改完之后,需要重启mysql服务
停用:
sudo /usr/local/mysql/bin/mysqladmin shutdown
启用:
sudo /usr/local/mysql/bin/mysql_safe -user=mysql &
我的重启命令是:
查看mysql编码
重启mysql服务后
因为我的电脑命令进行了配置:在 vim ~/.bashrc最下面增加了一下一行:
想要让配置文件马上生效,需在终端执行:
source ~/.bashrc
所以,开启mysql,只需输入:mysql,然后输入密码。
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/ |
+--------------------------+----------------------------+