[置顶] CentOS7安装配置mysql5.7

时间:2022-10-07 21:07:29

CentOS7安装配置mysql5.7

环境介绍

  • 操作系统: CentOS7.0
  • MySQL版本:mysql-5.7.17-1.el7

准备

下载rpm包

本文主要介绍如何通过官方提供的RPM包安装mysql5.7, 安装前,请前往mysql官网下载mysql5.7的RPM安装包。我下载的是rpm的集合包:mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar

检查卸载mariadb-lib

#检查
[root@ares ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.35-3.el7.x86_64
#卸载
[root@ares ~]# rpm -e mariadb-libs-5.5.35-3.el7.x86_64 --nodeps

上传安装包到CentOS7并解压

[置顶]        CentOS7安装配置mysql5.7

其中,安装mysql-server, 需要以下几个必要的安装包:

  • mysql-community-client-5.7.17-1.el7.x86_64.rpm(依赖于libs)
  • mysql-community-common-5.7.17-1.el7.x86_64.rpm (依赖于common)
  • mysql-community-libs-5.7.17-1.el7.x86_64.rpm
  • mysql-community-server-5.7.17-1.el7.x86_64.rpm(依赖于common, client)

安装

安装依赖

安装上面四个包需要libaio的依赖, 需要通过以下命令安装:

#安装libaio
[root@ares mysql-5.7.17-1.el7.x86_64.rpm-bundle]# yum -y install libaio

安装mysql-server:

[root@ares mysql-5.7.17-1.el7.x86_64.rpm-bundle]# rpm -ivh mysql-community-common-5.7.17-1.el7.x86_64.rpm mysql-community-libs-5.7.17-1.el7.x86_64.rpm mysql-community-client-5.7.17-1.el7.x86_64.rpm mysql-community-server-5.7.17-1.el7.x86_64.rpm 
warning: mysql-community-common-5.7.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-common-5.7.17-1.e################################# [ 25%]
2:mysql-community-libs-5.7.17-1.el7################################# [ 50%]
3:mysql-community-client-5.7.17-1.e################################# [ 75%]
4:mysql-community-server-5.7.17-1.e################################# [100%]
[root@ares mysql-5.7.17-1.el7.x86_64.rpm-bundle]#

初始化数据库

[root@ares mysql-5.7.17-1.el7.x86_64.rpm-bundle]mysqld --initialize #在/var/log/mysqld.log生成随机密码

更改mysql数据库所属于用户及其所属于组

[root@ares mysql]# chown mysql:mysql /var/lib/mysql -R

启动mysql数据库

#启动mysql数据库
[root@ares mysql]# systemctl start mysqld.service
# 到/root目录下寻找.mysql_secret文件
[root@ares ~]# cat .mysql_secret
# Password set for user 'root@localhost' at 2017-04-01 03:08:05
=%Tyw*p&(wb
# 更改root用户密码,新版的mysql在第一次登录后更改密码前是不能执行任何命令的
[root@ares ~]# mysql -u root -p '=%Tyw*p&(wbl'

更改密码

#更改密码:
mysql> set password=password('Love88me');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
mysql> grant all privileges on *.* to root@'%' identified by 'Love88me' with grant option;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

防火墙配置远程访问

#开放3306端口号
[root@ares ~]# firewall-cmd --permanent --add-port=3306/tcp
#重新加载防火墙
[root@ares ~]# firewall-cmd --reload
# 查看防火墙配置,可以看出3306已经在例外了
[root@ares ~]# firewall-cmd --list-all
public (default, active)
interfaces: enp0s3 enp0s8
sources:
services: dhcpv6-client ftp ssh
ports: 3306/tcp
masquerade: no
forward-ports:
icmp-blocks:
rich rules:

注意

新版的mysql数据库下的user表中已经没有Password字段了,而是将加密后的用户密码存储于authentication_string字段