linux修改mysql字符集编码

摘要:本文适用于mysql5.5 mysql5.6  其他版本未测试 mysql -u帐号 -p密码  登录mysql mysql>SHOW VARIABLES LIKE 'character%'; 查看当前字符集编码方式 MySQL [(none)]> SHOW VARIABLES LIKE 'cha

本文适用于mysql5.5 mysql5.6  其他版本未测试

mysql -u帐号 -p密码  登录mysql

mysql>SHOW VARIABLES LIKE 'character%';查看当前字符集编码方式

MySQL [(none)]> SHOW VARIABLES LIKE 'character%';

+--------------------------+----------------------------------+

| Variable_name | Value |

+--------------------------+----------------------------------+

| character_set_client | latin1 |

| character_set_connection | latin1 |

| character_set_database | gbk |

| character_set_filesystem | binary |

| character_set_results | latin1 |

| character_set_server | gbk |

| character_set_system | utf8 |

| character_sets_dir | /usr/local/mysql/share/charsets/ |

+--------------------------+----------------------------------+

8 rows in set (0.01 sec)

我这里是gbk,现在改成utf8,反之同理

编辑/etc/my.cnf文件

在[client]字段下增加default-character-set = utf8

在[mysqld]字段下增加character-set-server = utf8

在[mysql]字段下增加default-character-set = utf8

注:在mysql字段增加这段后,发现mysql重启报错,于是把这段去掉,mysql就正常了,但是后来我又继续尝试了次,就没有报错,不知道什么问题。

修改完成后需要重启mysql服务!

然后在#mysql -u帐号 -p密码 登录mysql

mysql>SHOW VARIABLES LIKE 'character%';

MySQL [(none)]> 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/local/mysql/share/charsets/ |

+--------------------------+----------------------------------+

8 rows in set (0.01 sec)

此时数据库编码改成utf8

linux修改mysql字符集编码_第1张图片

用云栖社区APP,舒服~

原文链接

你可能感兴趣的:(linux修改mysql字符集编码)