Centos7下载安装MySQL5.7

本文档详细记录了在CentOS7系统上安装MySQL5.7的过程,包括查看系统信息,卸载自带的MariaDB,下载并安装MySQL组件,解决依赖问题,启动MySQL服务,设置临时密码,修改root密码,授权远程登录,以及开启3306端口。
摘要由CSDN通过智能技术生成

一、查看Linux版本和系统内核

[root@localhost ~]# cat /etc/redhat-release   查看版本
CentOS Linux release 7.9.2009 (Core)
[root@localhost ~]# uname -r      查看内核
3.10.0-1160.el7.x86_64

二、下载对应的MySQL

MySQL官网:https://www.mysql.com/downloads/

1)

å¨è¿éæå¥å¾çæè¿°

2)

å¨è¿éæå¥å¾çæè¿°

3)å¨è¿éæå¥å¾çæè¿°

4)å¨è¿éæå¥å¾çæè¿° 

5)å¨è¿éæå¥å¾çæè¿° 

3.接下来,首先要卸载Centos7 自带的mariadb. 

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

4.上传到Centos服务上任意文件夹下,tar -xvf myql-xxx.tar 解压

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

5.rpm命令安装MySQL组件,使用rpm -ivh file 进行安装,按照依赖关系安装,依赖关系依次是common ->libs ->client ->server

[root@localhost ~]#  rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
warning: mysql-community-common-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-5.7.28-1.e################################# [100%]
[root@localhost ~]# rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
warning: mysql-community-libs-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-5.7.28-1.el7################################# [100%]
[root@localhost ~]# rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-5.7.28-1.e################################# [100%]
[root@localhost ~]# rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
	/usr/bin/perl is needed by mysql-community-server-5.7.28-1.el7.x86_64
	net-tools is needed by mysql-community-server-5.7.28-1.el7.x86_64
	perl(Getopt::Long) is needed by mysql-community-server-5.7.28-1.el7.x86_64
	perl(strict) is needed by mysql-community-server-5.7.28-1.el7.x86_64
[root@localhost ~]# 

6.当安装到mysql-community-server 报错了,这是缺少依赖,安装对应的依赖后再安装

yum install -y perl net-tools
rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm

7.安装完成后,会生成几个文件,如下所示:

[root@localhost ~]# ls /etc/ | grep my
my.cnf
my.cnf.d
[root@localhost ~]# ls /var/lib/ | grep my
mysql
mysql-files
mysql-keyring
[root@localhost ~]# ls /var/log/ | grep my
mysqld.log
[root@localhost ~]# ls /var/run/ | grep my
mysqld

8.启动

[root@localhost ~]# systemctl start mysqld.service
[root@localhost ~]# systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-09-04 11:22:51 EDT; 15s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 2163 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 2114 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 2166 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─2166 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Sep 04 11:22:47 localhost.localdomain systemd[1]: Starting MySQL Server...
Sep 04 11:22:51 localhost.localdomain systemd[1]: Started MySQL Server.
[root@localhost ~]# 

9.查看临时密码

[root@localhost ~]# grep 'password' /var/log/mysqld.log 
2021-09-04T15:22:48.784399Z 1 [Note] A temporary password is generated for root@localhost: e4,28U*G9AtW
[root@localhost ~]# 

10.mysql -u root -p 输入日志中的密码登录,修改密码

mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> alter user user() identified by 'root';
Query OK, 0 rows affected (0.00 sec)

mysql> 

11.授权远程登录

mysql> grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

mysql> 

12.开通3306端口

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cstpoo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值