---
title: "centos7.4上安装mysql5.7记录"
author: "白云天"
date: "2018-03-13T15:46:05Z"
tags: []
categories: ["开源软件"]
slug: "centos7-4-mysql5-7"
draft: false
lastmod: "2018-03-13T15:46:05Z"
id: 2412972
url: "https://iwin.iteye.com/blog/2412972"
---

### 准备

CentOS7默认安装了和MySQL有兼容性的MariaDB数据库，在我们安装MySQL5.7之前为了避免发生冲突首先删除MariaDB。

```
# rpm -qa | grep maria
mariadb-libs-5.5.50-1.el7_2.x86_64

# yum remove mariadb-libs -y
```

### []()添加MySQL的yum源

在CentOS7上yum安装MySQL需使用[MySQL的yum源](http://dev.mysql.com/downloads/repo/yum/)。执行以下命令首先添加MySQL的yum源。

```
# yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
```

添加MySQL的yum源之后可以使用`yum info命令`搜索mysql-community-server，确认详细的信息。

```
# yum info mysql-community-server
Available Packages
Name        : mysql-community-server
Arch        : x86_64
Version     : 5.7.14
Release     : 1.el7
Size        : 152 M
Repo        : mysql57-community/x86_64
Summary     : A very fast and reliable SQL database server
URL         : http://www.mysql.com/
License     : Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Under GPLv2 license as shown in the Description field.
Description : ........
```

### []()安装MySQL5.7

以上yum info命令是2016年8月28日的执行结果，当前安装的MySQL版本是5.7.14。确认安装版本之后执行以下命令进行安装。

```
# yum install mysql-community-server -y
```

到此MySQL5.7安装就完成了，接下来确认安装的MySQL版本。

```
# mysqld --version
mysqld  Ver 5.7.14 for Linux on x86_64 (MySQL Community Server (GPL))
```

### []()启动及停止MySQL

完成安装步骤之后，首先配置MySQL的开机自动启动，在这里使用`systemctl命令`。

```
# systemctl enable mysqld.service
```

接着使用`systemctl start mysqld.service`命令启动MySQL。

```
# systemctl start mysqld.service
```

而停止MySQL时使用`systemctl stop mysqld.service`命令。

```
# systemctl stop mysqld.service
```

以上是在CentOS7.2安装MySQL Community Server 5.7的步骤，但仅限于安装后续还需要根据开发的系统进行配置。

MySQL5.7开始MySQL管理用户root的密码，会默认生成并记录到`/var/log/mysqld.log`文件里，不要忘记修改默认密码。