码迷,mamicode.com
首页 > 数据库 > 详细

linux修改配置文件解决mysql中文乱码和指定数据库存储引擎

时间:2019-12-23 18:55:18      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:span   ice   显示乱码   中文乱码   class   centos   保存   mys   --   

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

 

  修改配置文件:

[root@VM_0_14_centos ~]# vi /etc/my.cnf 

[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

#字符集指定为utf8
character-set-server=utf8

#字符集的校对规则为utf8
collation-server=utf8_general_ci

#存储引擎
default-storage-engine=InnoDB

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

 

  标黄的都是新增的配置,接着保存好配置文件,重启mysql让设置生效:

[root@centos ~]# service mysqld restart
Stopping mysqld:  [  OK  ]
Starting mysqld:  [  OK  ]

   

  登陆mysql,看下存储引擎:

mysql> show variables like %storage_engine%;
+----------------+--------+
| Variable_name  | Value  |
+----------------+--------+
| storage_engine | InnoDB |
+----------------+--------+
1 row in set (0.00 sec)

 

  再看字符编码:

mysql> show variables like %character_set%;
+--------------------------+----------------------------+
| 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     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

 

  我们发现还有一个character_set_database是ISO-8859-1,改掉:

mysql> alter database `prize` character set utf8 collate utf8_general_ci;
Query OK, 1 row affected (0.00 sec)

mysql> show variables like %character_set%;
+--------------------------+----------------------------+
| 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.00 sec)

 

  现在把老的乱码数据删掉,重新插入就可以展示了:

技术图片

 

 

 

  

linux修改配置文件解决mysql中文乱码和指定数据库存储引擎

标签:span   ice   显示乱码   中文乱码   class   centos   保存   mys   --   

原文地址:https://www.cnblogs.com/wuxun1997/p/12084881.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!