欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

ubuntu12.04 修改mysql配置文件my.cnf编码出错---解决方法

程序员文章站 2022-05-21 12:32:07
...

------------------------------------------------------ | Variable_name | Value | ------------------------------------------------------ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 |

+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

character_set_database和character_set_server的编码还是继承自编译的

直接修改配置文件 my.cnf:[mysqld]下添加default-character-set=utf8

$sudo service mysql restart

mysql stop/waiting
start: Job failed to start
服务竟然起不来

升级ubuntu12.04以后才第一次碰到

最简单的办法是只要在[mysqld]下再加两条配置即可:加上之后如下

default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci

$sudo service mysql start
mysql start/running, process 22704

$mysql -u root -p
Enter password:

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/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)
编码就顺利改掉了。