环境:ubuntu mate16.04
sudo apt-get install mysql-server #安装mysql
网上大部分的修改编码还是在/etc/mysql/my.cnf中
而且让打开my.cnf后,在文件内的[mysqld]下增加如下两行设置。但是。
#查看my.cnf内容
cat /etc/mysql/my.cnf
里面并没有[mysqld]
修改方法一: 在my.cnf中添加
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
修改方法二:
在my.cnf底部可以看到
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
说明配置被包含在这两个文件夹中。
经过查看,确定在/etc/mysql/mysql.conf.d/ 下
cd /etc/mysql/mysql.conf.d/
sudo gedit mysqld.cnf
找到[mysqld]
在下面任意处添加:
##add myself
character_set_server=utf8
init_connect='SET NAMES utf8'
##add myself
sudo service mysql restart
登录mysql
$mysql -u root -p
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/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)
完成mysql utf-8字符编码设置。