CentOS 查看和修改 MySQL 字符集

Posted 一像素

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS 查看和修改 MySQL 字符集相关的知识,希望对你有一定的参考价值。

客户提供了mysql的环境,但是不支持中文,

通过以下命令查看了MySQL的字符集

连接上 mysql 服务,输入以下命令

mysql> show variables like ‘character_set%‘;

显示如下:

+--------------------------+----------------------------+  
| 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 支持中文,需要把字符集改变成 UTF8,

方法如下:

1. 打开etc/my.cnf

2. 修改成如下内容,保存

[client]  
port=3306  
socket=/var/lib/mysql/mysql.sock  
default-character-set=utf8  
  
[mysqld]  
datadir=/var/lib/mysql  
socket=/var/lib/mysql/mysql.sock  
user=mysql  
# Disabling symbolic-links is recommended to prevent assorted security risks  
symbolic-links=0  
character-set-server=utf8  
  
[mysql]  
no-auto-rehash  
default-character-set=utf8  
  
[mysqld_safe]  
log-error=/var/log/mysqld.log  
pid-file=/var/run/mysqld/mysqld.pid 

3. 重启 mysql 服务:service mysqld restart

再次查看 mysql 编码,已经更新成如下信息

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

  

以上是关于CentOS 查看和修改 MySQL 字符集的主要内容,如果未能解决你的问题,请参考以下文章

mysql 字符编码的查看与修改

coentos mysql 重启_Centos7安装mysql,查看并修改默认登陆账户和密码

Centos 首次运行MySQL

在Linux中安装MySQL

CentOS修改Mysql字符集

MySQL查看和修改字符集