Yum安装MySQL8.0版本

不管现实多么惨不忍睹,都要持之以恒地相信,这只是黎明前短暂的黑暗而已。不要惶恐眼前的难关迈不过去,不要担心此刻的付出没有回报,别再花时间等待天降好运。真诚做人,努力做事!你想要的,岁月都会给你。Yum安装MySQL8.0版本,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

实验环境

  • 操纵系统:Centos7.6

  • IP地址:192.168.66.61

  • 内存:2G

  • CPU:4C

  • 提前关闭selinux和防火墙

  • 配置yum源

  • 网络能够通

[root@localhost etc]# systemctl status firewalld		##查看防火墙状态,显示Active: inactive (dead)表示防火墙未开启
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 二 2023-04-11 21:43:16 CST; 21h ago
     Docs: man:firewalld(1)
 Main PID: 838 (firewalld)
    Tasks: 2
   CGroup: /system.slice/firewalld.service
           └─838 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

4月 11 21:43:15 localhost.localdomain systemd[1]: Starting firewalld - dynam...
4月 11 21:43:16 localhost.localdomain systemd[1]: Started firewalld - dynami...
4月 11 21:43:16 localhost.localdomain firewalld[838]: WARNING: AllowZoneDrif...
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost etc]# systemctl stop firewalld	#关闭防火墙
[root@localhost etc]# systemctl start firewalld	#开启防火墙
[root@localhost etc]# firewall-cmd --list-ports --permanent	#查看开放端口

[root@localhost etc]# firewall-cmd --add-port=3306/tcp --permanent
success
[root@localhost etc]# firewall-cmd --add-port=3306/udp --permanent
success
[root@localhost etc]# firewall-cmd --reload	#防火墙重新加载配置
success
[root@localhost etc]# systemctl restart firewalld	#重新启动防火墙
[root@localhost etc]# iptables -L -n

一、配置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]# cd /etc/yum.repos.d
[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)

3.设置远程登录

进入配置库

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

更改表数据

mysql> update user set host = '%' where host = 'localhost' and user = 'root';
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0

更新配置文件

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/160678.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!