Linux认证考试:Linux系统下的MySQL数据库服务器字符集设置
启动MySQL后,以root登录mysql
isher@isher-ubuntu:~$ mysql -u root
》show variables like ‘character%’; #执行编码显示
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
在某些时候,我们续要修改mysql默认数据库的编码,以保证某些迁移的程序可以正常显示,编辑f文件进行编码修改,windows可以直接用Mysql Server Instance Config Wizard 进行设置
在linux下修改3个f的1个/etc/mysql/f文件
找到客户端配置[client] 在下面添加
default-character-set=utf8 默认字符集为utf8
在找到[mysqld] 添加
default-character-set=utf8 默认字符集为utf8
init_connect=‘SET NAMES utf8’ (设定连接mysql数据库时使用utf8编码,以让mysql数据库为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/ |
+--------------------------+----------------------------+
此方法用于标准mysql版本同样有效,对于/etc/f文件,需要从mysql/support-files的文件夹cp my-f一份到/etc/f
对于Ubuntu的用户,如果是使用 Synaptic 安装的,则直接在 /etc/mysql/f