用rpm包在centos7.4上安装mysql-5.7.29-1.el7.x86_64

Posted yisheng163

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用rpm包在centos7.4上安装mysql-5.7.29-1.el7.x86_64相关的知识,希望对你有一定的参考价值。

一,准备工作。

 

查看系统版本:

[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core) 
[root@localhost ~]#

mysql的rpm包下载地址

https://dev.mysql.com/downloads/mysql/5.7.html#downloads

下载,mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar 大小520.5M

 

卸载CentOS7.4系统自带的mariadb

[root@localhost ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
[root@localhost ~]# rpm -qa|grep mariadb
[root@localhost ~]# 

将mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar 拷贝到/tmp下,并解压

解压

[root@localhost tmp]# tar xvf mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar 
mysql-community-embedded-devel-5.7.29-1.el7.x86_64.rpm
mysql-community-test-5.7.29-1.el7.x86_64.rpm
mysql-community-embedded-5.7.29-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.29-1.el7.x86_64.rpm
mysql-community-libs-5.7.29-1.el7.x86_64.rpm
mysql-community-client-5.7.29-1.el7.x86_64.rpm
mysql-community-server-5.7.29-1.el7.x86_64.rpm
mysql-community-devel-5.7.29-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.29-1.el7.x86_64.rpm
mysql-community-common-5.7.29-1.el7.x86_64.rpm

依次安装:

mysql-community-common-5.7.29-1.el7.x86_64.rpm、
mysql-community-libs-5.7.29-1.el7.x86_64.rpm、
mysql-community-client-5.7.29-1.el7.x86_64.rpm、
mysql-community-server-5.7.29-1.el7.x86_64.rpm

安装common

[root@localhost tmp]# rpm -ivh mysql-community-common-5.7.29-1.el7.x86_64.rpm 
warning: mysql-community-common-5.7.29-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-5.7.29-1.e################################# [100%]
[root@localhost tmp]# 

安装libs

[root@localhost tmp]# rpm -ivh mysql-community-libs-5.7.29-1.el7.x86_64.rpm 
warning: mysql-community-libs-5.7.29-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-5.7.29-1.el7################################# [100%]
[root@localhost tmp]#

安装client

[root@localhost tmp]# rpm -ivh mysql-community-client-5.7.29-1.el7.x86_64.rpm 
warning: mysql-community-client-5.7.29-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-5.7.29-1.e################################# [100%]
[root@localhost tmp]# 

安装server

[root@localhost tmp]# rpm -ivh mysql-community-server-5.7.29-1.el7.x86_64.rpm 
warning: mysql-community-server-5.7.29-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-5.7.29-1.e################################# [100%]
[root@localhost tmp]# 

这一步如如果报错,缺依赖的问题,需要挂载CentOS7.4的系统iso镜像,安装perl依赖、net-tools依赖

重启系统,来启动mysql服务

[root@localhost tmp]# reboot

 查看防火墙端口,开放3306端口

[root@localhost ~]# firewall-cmd --query-port=3306/tcp
no
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --query-port=3306/tcp
yes
[root@localhost ~]#

 设置数据库日志过期天数为14天

 

获取mysql的root用户的初始密码

[root@localhost ~]# grep \'password\' /var/log/mysqld.log 
2020-01-14T01:09:01.515663Z 1 [Note] A temporary password is generated for root@localhost: vx*biwua,8/Q
[root@localhost ~]# 

以获取mysql的root用户的初始密码登录数据库

[root@localhost ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \\g.
Your MySQL connection id is 5
Server version: 5.7.29

修改root密码

mysql> alter user \'root\'@\'localhost\' identified by \'2020root$PWD\';
Query OK, 0 rows affected (0.01 sec)

mysql> 

使密码即时生效

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

mysql> 

允许以root身份远程登录mysql

mysql> GRANT ALL PRIVILEGES ON *.* TO \'root\'@\'%\' IDENTIFIED BY \'2020root$PWD\' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> 

修改mysql的字符集为utf8
编辑文件/etc/my.conf,设置字符集为utf8

vi /etc/my.cnf

 

重起mysql服务

[root@localhost ~]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service
[root@localhost ~]# 

测试登陆

 

以上是关于用rpm包在centos7.4上安装mysql-5.7.29-1.el7.x86_64的主要内容,如果未能解决你的问题,请参考以下文章

CentOS7.4下MySQL5.7.28二进制方式安装

centos 7 安装 mysql 5.7

CentOS7.4下MySQL5.7.28源码方式安装

MySQL基础CentOS 7.4 RPM方式安装MySQL 5.7.19

Mysql zip包在Windows上安装配置

MySQL 5.7.20在RedHat 7.2上通过RPM包安装