Yum安装MySQL8.0版本

Yum安装MySQL8.0版本

实验环境

  • 操纵系统:Centos7.6
  • IP地址:192.168.66.61
  • 内存:2G
  • CPU:4C
  • 提前关闭selinux和防火墙
  • 配置yum源
  • 网络能够通
#关闭SElinux
[root@localhost ~]# setenforce 0 				#临时关闭
[root@localhost ~]# vim /etc/selinux/config 	#永久关闭
修改内容
SELINUX=disabled
[root@localhost ~]# getenforce 				#获取状态
Disabled

#关闭防火墙
[root@localhost ~]# systemctl status firewalld.service	#查看firewall状态
[root@localhost ~]# systemctl stop firewalld.service 		#关闭
[root@localhost ~]# systemctl disable firewalld.service 	#设置开机不启动
[root@localhost ~]# iptables -F							#清空防火墙规则

一、配置yum源

1.先备份Centos-Base.repo,然后从阿里云下载centos7-repo

  • 备份本地yum源

[root@localhost ~]# mv /etc/yum.repos.d/CentOS-Base.repo  /etc/yum.repos.d/CentOS-Base.repo.bak
  • 下载阿里云的yum源

[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2023-03-12 17:24:42--  http://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 117.169.106.235, 117.169.106.236, 117.169.106.237, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|117.169.106.235|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”

100%[===============>] 2,523       --.-K/s 用时 0.007s  

2023-03-12 17:24:43 (361 KB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])

#可选择执行或不执行
[root@localhost yum.repos.d]# yum clean all
[root@localhost yum.repos.d]# yum makecache

2.安装之前的环境检查

在Centos7的系统上默认是mariadb,如果要安装MySQL需要先把系统中存在的MySQL或者mariadb删除掉。

  • 查看是否已经安装MySQL或mariadb,如果已经安装先删除

[root@localhost ~]# rpm -qa |grep mariadb
mariadb-server-5.5.60-1.el7_5.x86_64
mariadb-libs-5.5.60-1.el7_5.x86_64
mariadb-5.5.60-1.el7_5.x86_64
[root@localhost ~]# yum -y remove mariadb*
  • 再次查看是否还有残留,如果有就删除

[root@localhost ~]# rpm -qa |grep mysql
qt-mysql-4.8.7-2.el7.x86_64
[root@localhost ~]# rpm -e qt-mysql-4.8.7-2.el7.x86_64
  • MySQL和mariadb都要查看

[root@localhost ~]# rpm -qa |grep maraidb
[root@localhost ~]# rpm -qa |grep mysql
  • 最后查看老版本中MySQL相关的安装目录

[root@localhost ~]# find / -name mysql
/etc/selinux/targeted/active/modules/100/mysql
/usr/lib64/mysql
/usr/lib64/perl5/vendor_perl/auto/DBD/mysql
/usr/lib64/perl5/vendor_perl/DBD/mysql
/usr/share/mysql
[root@localhost ~]# rm -rf /etc/selinux/targeted/active/modules/100/mysql
[root@localhost ~]# rm -rf /usr/lib64/mysql
[root@localhost ~]# rm -rf /usr/lib64/perl5/vendor_perl/auto/DBD/mysql
[root@localhost ~]# rm -rf /usr/lib64/perl5/vendor_perl/DBD/mysql
[root@localhost ~]# rm -rf /usr/share/mysql

3.下载MySQ8.0的包

下载MySQL8.0comunity的包

如果没有wget,需要先安装wget,再使用wget下载

[root@localhost ~]# yum -y install wget
[root@localhost ~]# wget https://repo.mysql.com//mysql80-community-release-el7-7.noarch.rpm
[root@localhost ~]# ls
anaconda-ks.cfg
mysql80-community-release-el7-7.noarch.rpm

使用rpm -ivh 安装刚刚下载的rpm包

[root@localhost ~]# rpm -ivh mysql80-community-release-el7-7.noarch.rpm
警告:mysql80-community-release-el7-7.noarch.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql80-community-release-el7-7  ################################# [100%]

这时候会看到生成了几个与MySQL相关的repo的包

[root@localhost yum.repos.d]# ls
back                   CentOS-Media.repo
CentOS-Base.repo       CentOS-Sources.repo
CentOS-Base.repo.bak   CentOS-Vault.repo
CentOS-CR.repo         mysql-community.repo
CentOS-debuginfo.repo  mysql-community-source.repo
CentOS-fasttrack.repo

4.使用yum安装

意这里需要关闭校验

[root@localhost yum.repos.d]# vim mysql-community.repo
gpgcheck=0	改为0不校验
#gpgcheck表示安装rpm包时,是否基于公私钥对匹配包的安全信息,1表示开启,0表示关闭,此项不写默认为验证

解释:
enabled=1
#enabled表示当前仓库是否开启,1为开启,0为关闭,此项不写默认为开启

gpgcheck=0
#gpgcheck表示安装rpm包时,是否基于公私钥对匹配包的安全信息,1表示开启,0表示关闭,此项不写默认为验证

直接使用yum安装即可

[root@localhost yum.repos.d]# yum -y install mysql-community-server

出现如图的内容表示安装成功:
在这里插入图片描述

5.启动并测试

先启动,然后查看运行状态:

[root@localhost ~]# systemctl restart mysqld
[root@localhost ~]# systemctl status mysqld |grep active
   Active: active (running) since 日 2023-03-12 23:32:06 CST; 23s ago
[root@localhost ~]# ps -ef |grep mysqld |grep -v grep
mysql      7837      1  3 23:32 ?        00:00:02 /usr/sbin/mysqld
[root@localhost ~]# netstat -antlp |grep mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      7837/mysqld         
tcp6       0      0 :::33060                :::*                    LISTEN      7837/mysqld 

查看版本:

[root@localhost ~]# mysql -V
mysql  Ver 8.0.32 for Linux on x86_64 (MySQL Community Server - GPL)

二. 设置新密码并重新启动

1.设置新密码

MySQL的密码并不是默认为空,而是在启动的时候,默认在log日志中生成密码,可以通过命令查看到密码:

[root@localhost ~]# grep "temporary password" /var/log/mysqld.log
2023-03-12T15:32:02.523097Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: yH?LuwE2f<>+

在这里插入图片描述
随机密码难记,可以设置自己的密码

登录数据库

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

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

修改密码

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


执行 flush privileges; 使密码生效

mysql> flush privileges;

mysql> quit
Bye

注意: 这里的密码如果设置的过于简单也会报错,要设置的复杂一点,密码长度大于8位数

2.重新登录测试

[root@localhost ~]# mysql -uroot -pLilinbo123!
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.32 MySQL Community Server - GPL

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database lilibo;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| lilibo             |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.01 sec)

可以看到,数据库已经能够正常使用了,接下来,就开启MySQL学习之旅吧。

猜你喜欢

转载自blog.csdn.net/m0_67159981/article/details/129655038