[root@localhost ~]# mysql -uroot -p123qqq...A
...
mysql> show variables like '%char%';
+--------------------------------------+----------------------------+
| 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/ |
| validate_password_special_char_count | 1 |
+--------------------------------------+----------------------------+
9 rows in set (0.03 sec)
可以看到目前一部分默认的字符集编码为latin1
。
[root@localhost ~]# cp /etc/my.cnf /etc/my.cnf.bak //备份mysql配置文件my.cnf
[root@localhost ~]# vim /etc/my.cnf
[mysqld]
character-set-server=utf8 //新增配置项
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[client] //新增配置项
default-character-set=utf8 //新增配置项
[mysql] //新增配置项
default-character-set=utf8 //新增配置项
[root@localhost ~]# service mysqld restart //重启mysql服务
停止 mysqld: [确定]
正在启动 mysqld: [确定]
[root@localhost ~]# mysql -uroot -p123qqq...A
...
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/ |
| validate_password_special_char_count | 1 |
+--------------------------------------+----------------------------+
9 rows in set (0.00 sec)
可以看到现在字符集编码已经被修改为utf8
了。