檢視當前字符集編碼
[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。
修改字符集為utf8[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/mysqlsocket=/var/lib/mysql/mysql.socksymbolic-links=0log-error=/var/log/mysqld.logpid-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了。
最新評論