---
title: "分布式系统-基础篇-CentOS7 安装mysql5.6"
author: "shusanzhan"
date: "2017-02-13T23:11:50Z"
tags: []
categories: ["互联网"]
slug: "centos7-mysql5-6"
draft: false
lastmod: "2017-02-13T23:12:20Z"
id: 2356921
url: "https://shusanzhan.iteye.com/blog/2356921"
---

# 一、官网下载安装mysql-server

## 1、安装mysql

\# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

\# rpm -ivh mysql-community-release-el7-5.noarch.rpm

\# yum install mysql-community-server

 

## 2、重启mysql服务

```
# service mysqld restart
```

## 3、登陆mysql

```
# mysql -u root
```

## 4、设置登陆密码

```
# set password for 'root'@'localhost' =password('ryqc2016RYQC');
```

# 二、配置mysql

## 1、编码

mysql配置文件为/etc/my.cnf

最后加上编码配置

```
# vi /etc/my.cnf
```

在文件末尾添加：

```
[mysql]
```

```
default-character-set =utf8
```

## 2、远程连接设置

把在所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户。

```
mysql>grant all privileges on *.* to root@'%'identified by 'password';
```

```
 
```

```
如果是新用户而不是root，则要先新建用户
```

```
 
```

```
mysql> create user 'username'@'%' identified by 'password'; 
```

```
 
```

```
 
```

# 三、默认配置

&lt;!--\[if !supportLists]--&gt;1.  &lt;!--\[endif]--&gt;\[client]  

&lt;!--\[if !supportLists]--&gt;2.  &lt;!--\[endif]--&gt;password        = 123456  

&lt;!--\[if !supportLists]--&gt;3.  &lt;!--\[endif]--&gt;port            = 3306  

&lt;!--\[if !supportLists]--&gt;4.  &lt;!--\[endif]--&gt;default-character-set=utf8  

&lt;!--\[if !supportLists]--&gt;5.  &lt;!--\[endif]--&gt;\[mysqld]  

&lt;!--\[if !supportLists]--&gt;6.  &lt;!--\[endif]--&gt;port            = 3306  

&lt;!--\[if !supportLists]--&gt;7.  &lt;!--\[endif]--&gt;character\_set\_server=utf8  

&lt;!--\[if !supportLists]--&gt;8.  &lt;!--\[endif]--&gt;character\_set\_client=utf8  

&lt;!--\[if !supportLists]--&gt;9.  &lt;!--\[endif]--&gt;collation-server=utf8\_general\_ci  

&lt;!--\[if !supportLists]--&gt;10.&lt;!--\[endif]--&gt;#(注意linux下mysql安装完后是默认：表名区分大小写，列名不区分大小写； 0：区分大小写，1：不区分大小写)  

&lt;!--\[if !supportLists]--&gt;11.&lt;!--\[endif]--&gt;lower\_case\_table\_names=1  

&lt;!--\[if !supportLists]--&gt;12.&lt;!--\[endif]--&gt;#(设置最大连接数，默认为 151，MySQL服务器允许的最大连接数16384; )  

&lt;!--\[if !supportLists]--&gt;13.&lt;!--\[endif]--&gt;max\_connections=1000  

&lt;!--\[if !supportLists]--&gt;14.&lt;!--\[endif]--&gt;\[mysql]  

&lt;!--\[if !supportLists]--&gt;15.&lt;!--\[endif]--&gt;default-character-set = utf8  

# 四、开启防火墙

## 1、开启防火墙

firewall-cmd --zone=public --add-port=3306/tcp --permanent

## 2、重启防火墙

*systemctl restart firewalld.service*