RedHat Linux下修改MySQL编码方式

RedHat Linux安装Mysql后其默认编码如下:

(运行如下命令即可查看编码方式)

# mysql -u root -p

Enter password:

mysql > 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/ |
+--------------------------+----------------------------+

1.要修改编码方式则找到mysql安装目录下的配置文件(.cnf文件),一般至少有四个配置文件:mysql-huge.cnf mysql-medium.cnf  mysql-small.cnf mysql mysql-large.cnf  这四个配置文件我们只需拷贝其中一个文件到目录/etc下并重命名为my.cnf,若不拷贝到此目录下则重启Mysql后编码方式又回到默认方式,就是因为这个我整了半天。只要拷贝到/etc目录下就永久的修改了编码方式。

2.修改文件my.cnf:

找到客户端配置[client] 在下面添加
default-character-set=utf8 默认字符集为utf8
在找到[mysqld] 添加
default-character-set=utf8 默认字符集为utf8

init_connect=SET NAMES 'utf8'

3.重启Mysql:

# service mysql restart

再查看编码方式即改为了所需编码方式,如下:

+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/25812.html