---
title: "Ubuntu中MySQL5.7设置utf8编码格式步骤"
author: "hetaoo"
date: "2016-12-14T00:37:11Z"
tags: []
categories: ["操作系统"]
slug: "ubuntu-mysql5-7-utf8"
draft: false
lastmod: "2016-12-14T00:37:11Z"
id: 2344761
url: "https://hetaoo.iteye.com/blog/2344761"
---

## 1.Ctrl+t打开终端

## 2.输入mysql -u root -p 命令，进入MySQL

## 输入 SHOW VARIABLES LIKE 'char%'; 查看MySQL编码，有两个不是utf8

## [![Ubuntu中MySQL5.7设置utf8编码格式步骤_第1张图片](http://img.it610.com/image/info5/b3c02237c82c49eaa01b6bb671313c0a.png)](http://img.it610.com/image/info5/b3c02237c82c49eaa01b6bb671313c0a.png)

 

## 3.在终端中输入 sudo gedit /etc/mysql/mysql.conf.d/mysqld.cnf  命令

[![Ubuntu中MySQL5.7设置utf8编码格式步骤_第2张图片](http://img.it610.com/image/info5/3e31387fee9c4e5e8c25f72c6c6a4fa0.jpg)](http://img.it610.com/image/info5/3e31387fee9c4e5e8c25f72c6c6a4fa0.jpg)

打开mysqld.cnf 文件，在lc-messages-dir= /usr/share/mysql 语句后添加 character-set-server=utf8 语句

#### [![Ubuntu中MySQL5.7设置utf8编码格式步骤_第3张图片](http://img.it610.com/image/info5/345d8ea22ede46858cfd1b077306272b.jpg)](http://img.it610.com/image/info5/345d8ea22ede46858cfd1b077306272b.jpg)

 

## 4.在终端输入 sudo gedit /etc/mysql/conf.d/mysql.cnf 命令打开mysql.cnf配置文件，如图添加代码：default-character-set=utf8 如图：

[![Ubuntu中MySQL5.7设置utf8编码格式步骤_第4张图片](http://img.it610.com/image/info5/f3a53bd73c1b4e958dc0b36efea386a9.jpg)](http://img.it610.com/image/info5/f3a53bd73c1b4e958dc0b36efea386a9.jpg)

 

## 5.在终端中输入  /etc/init.d/mysql restart 命令重启MySQL服务，如图所示，重启成功。

[![Ubuntu中MySQL5.7设置utf8编码格式步骤_第5张图片](http://img.it610.com/image/info5/f9847301e76b49f69bc29dadce4b6e0f.jpg)](http://img.it610.com/image/info5/f9847301e76b49f69bc29dadce4b6e0f.jpg)

 

## 6.再次输入进入MySQL  输入 SHOW VARIABLES LIKE 'char%';  命令 ，显示修改成功

[![Ubuntu中MySQL5.7设置utf8编码格式步骤_第6张图片](http://img.it610.com/image/info5/0a002c6774324f9b8dc1636df3d4ee6a.png)](http://img.it610.com/image/info5/0a002c6774324f9b8dc1636df3d4ee6a.png)

 

[Ubuntu中MySQL5.7设置utf8编码格式步骤](http://www.it610.com/article/5184658.htm "Ubuntu中MySQL5.7设置utf8编码格式步骤")