Home > Database > Mysql Tutorial > body text

CentOS 6.5安装MySQL中文乱码问题解决

WBOY
Release: 2016-06-07 16:45:32
Original
961 people have browsed it

不管是Linux还是Windows都有新手遇到MySQL服务安装好了之后写入中文发现乱码,今天我装了个CentOS 6.5也遇到了这个问题,现在解决

不管是Linux还是Windows都有新手遇到MySQL服务安装好了之后写入中文发现乱码,,今天我装了个CentOS 6.5也遇到了这个问题,现在解决了,分享一下经验。

1.首先安装mysql,我很怕麻烦。。所以全给安装了一下,不管那么多依赖关系了,省心。

yum install -y mysql-server mysql mysql-devel

2.安装好了之后,启动看下是什么情况

service mysqld start

3.没啥问题,设置一下root密码,一开始root是没有密码的,所以我直接设置密码为123456

mysqladmin -u root password '123456'

4.登录进mysql看看是个什么情况。

mysql -u root -p

5.看下mysql的编码,发现不全是utf8,有Latin的,这是中文乱码的根源。

show variables like 'character%';

6.关闭mysql服务,准备开始修改my.cnf文件

service mysqld stop
vi /etc/my.cnf

7.看了网络上很多版本的my.cnf的修改方式,我索性就全给改成了utf8,我的my.cnf文件是这样的。

[mysqld]
default-character-set = utf8    #这个是我添加的
character_set_server=utf8      #这个是我添加的
init_connect='SET NAMES utf8'
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
symbolic-links=0
 
[mysqld_safe]
default-character-set = utf8    #这个是我添加的
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
 
[client]
default-character-set = utf8      #这个是我添加的
 
[mysql.server]
default-character-set = utf8      #这个是我添加的
 
[mysql]
default-character-set = utf8      #这个是我添加的
 

8.修改了my.cnf文件之后一定要重启mysql服务,这是必须的。

service mysqld restart
 

9.再进去mysql查看编码会发都变成了utf8,除了character_set_filesystem 是binary 。这个不用我解释是为什么了。

10,如果还发现乱码那可能是你的系统编码的问题或者是你的程序写入的问题了,妈妈再也不用担心我的学习了。

CentOS(Linux)中解决MySQL乱码

MySQL乱码问题终极指南

CentOS(Linux)中解决MySQL乱码

MySQL乱码问题深层分析

MySQL乱码问题的解决方法

本文永久更新链接地址:

linux

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!