本文主要详细介绍一下Linux下彻底解决MySQL中文乱码问题,一般乱码问题出现在服务器首次安装MySQL中。
Linux下彻底解决MySQL中文乱码
执行查询语句发现查询的数据中中文的都是乱码1
2
3
4
5
6
7//使用该命令查看编码,发现好多编码不是utf8
SHOW VARIABLES LIKE 'char%';
//修改编码
set character_set_results=utf8;
//再次查询发现乱码解决,但并不是永久解决,退出mysql再次登录mysql还是乱码
永久解决乱码问题1
cat /etc/mysql/mysql.conf.d/mysqld.cnf
可能不是该文件名,或者有些内容会有些出入,找到跟下图内容差不多的文件就可以,将红框的内容添加到文件中
修改完成之后保存并退出便可以永久生效
mysqld.cnf文件内容1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36[mysqld]
character-set-server=utf8
# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
#log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8