使用yum仓库安装MySQL8

1.查看centos系统版本

# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

2.下载并安装repo仓库文件

下载地址:https://dev.mysql.com/downloads/repo/yum/



# wget https://repo.mysql.com//mysql80-community-release-el7-5.noarch.rpm

# yum localinstall -y mysql80-community-release-el7-5.noarch.rpm
已加载插件:fastestmirror
正在检查 mysql80-community-release-el7-5.noarch.rpm: mysql80-community-release-el7-5.noarch
mysql80-community-release-el7-5.noarch.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql80-community-release.noarch.0.el7-5 将被 安装
--> 解决依赖关系完成 依赖关系解决 ================================================================================================
Package 架构 版本 源 大小
================================================================================================
正在安装:
mysql80-community-release noarch el7-5 /mysql80-community-release-el7-5.noarch 9.1 k 事务概要
================================================================================================
安装 1 软件包 总计:9.1 k
安装大小:9.1 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : mysql80-community-release-el7-5.noarch 1/1
验证中 : mysql80-community-release-el7-5.noarch 1/1 已安装:
mysql80-community-release.noarch 0:el7-5 完毕!

3.验证仓库软件


# yum makecache # yum repolist all|grep mysql8
mysql80-community/x86_64 MySQL 8.0 Community Server 启用: 321
mysql80-community-source MySQL 8.0 Community Server - So 禁用 # yum repolist enabled | grep "mysql*"
mysql-connectors-community/x86_64 MySQL Connectors Community 230
mysql-tools-community/x86_64 MySQL Tools Community 138
mysql80-community/x86_64 MySQL 8.0 Community Server 321

4.安装MySQL8

说明:此时仓库中只有一个MySQL版本,因此可以直接安装

# yum install -y mysql-community-server

# 使用以下方式检查安装包
# rpm -qa|grep -i "mysql.*8.*"
mysql80-community-release-el7-5.noarch
mysql-community-client-plugins-8.0.28-1.el7.x86_64
mysql-community-client-8.0.28-1.el7.x86_64
mysql-community-libs-compat-8.0.28-1.el7.x86_64
mysql-community-common-8.0.28-1.el7.x86_64
mysql-community-libs-8.0.28-1.el7.x86_64
mysql-community-icu-data-files-8.0.28-1.el7.x86_64
mysql-community-server-8.0.28-1.el7.x86_64

默认配置文件内容

# cat /etc/my.cnf

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html [mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

查看默认密码

yum方式安装的MySQL8卸载

使用rpm文件安装MySQL8

说明:使用rpm包的形式安装MySQL8需要下载多个rpm文件,但是官方已经提供好一个压缩包里,里面是所有的rpm文件,只需要下载这个压缩包就行了



tar xfc mysql-8.0.25-1.el7.x86_64.rpm-bundle.tar
rpm -i mysql-community-{server-8,client,common,libs}*

下载rpm安装软件

地址:https://dev.mysql.com/downloads/mysql/

使用通用二进制文件安装MySQL8

下载地址:https://dev.mysql.com/downloads/mysql/

1.安装依赖

mysql依赖libaio,如果未在本地安装,则数据目录初始化和后续的服务启动将失败

# 默认是已安装的

[root@localhost ~]# rpm -qa|grep libaio
libaio-0.3.109-13.el7.x86_64 # yum -y install libaio # 若不存在则安装

2.下载二进制安装文件

# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz

3.安装

# 添加mysql组和mysql用户,所有的文件和目录应该在mysql用户下
# groupadd mysql
# useradd -r -g mysql -s /bin/false mysql # 设置安装位置为/usr/local,可以修改为其他位置
# tar -xvf mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz -C /usr/local/ # 添加软链接,以后升级版本,只需要解压到相同的位置,更改符号链接就行了
# cd /usr/local/
# ll
总用量 0
drwxr-xr-x. 2 root root 6 4月 11 2018 bin
drwxr-xr-x. 2 root root 6 4月 11 2018 etc
drwxr-xr-x. 2 root root 6 4月 11 2018 games
drwxr-xr-x. 2 root root 6 4月 11 2018 include
drwxr-xr-x. 2 root root 6 4月 11 2018 lib
drwxr-xr-x. 2 root root 6 4月 11 2018 lib64
drwxr-xr-x. 2 root root 6 4月 11 2018 libexec
drwxr-xr-x 9 root root 129 3月 30 13:52 mysql-8.0.28-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 6 4月 11 2018 sbin
drwxr-xr-x. 5 root root 49 4月 9 2021 share
drwxr-xr-x. 2 root root 56 3月 30 13:47 src # ln -s mysql-8.0.28-linux-glibc2.12-x86_64 mysql # ll
总用量 0
drwxr-xr-x. 2 root root 6 4月 11 2018 bin
drwxr-xr-x. 2 root root 6 4月 11 2018 etc
drwxr-xr-x. 2 root root 6 4月 11 2018 games
drwxr-xr-x. 2 root root 6 4月 11 2018 include
drwxr-xr-x. 2 root root 6 4月 11 2018 lib
drwxr-xr-x. 2 root root 6 4月 11 2018 lib64
drwxr-xr-x. 2 root root 6 4月 11 2018 libexec
lrwxrwxrwx 1 root root 35 3月 30 13:53 mysql -> mysql-8.0.28-linux-glibc2.12-x86_64
drwxr-xr-x 9 root root 129 3月 30 13:52 mysql-8.0.28-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root 6 4月 11 2018 sbin
drwxr-xr-x. 5 root root 49 4月 9 2021 share
drwxr-xr-x. 2 root root 56 3月 30 13:47 src # 创建必要的目录并将所有权更改为mysql # cd mysql
# ll
总用量 284
drwxr-xr-x 2 7161 31415 4096 12月 18 02:28 bin
drwxr-xr-x 2 7161 31415 55 12月 18 02:28 docs
drwxr-xr-x 3 7161 31415 282 12月 18 02:28 include
drwxr-xr-x 6 7161 31415 201 12月 18 02:28 lib
-rw-r--r-- 1 7161 31415 276595 12月 18 00:07 LICENSE
drwxr-xr-x 4 7161 31415 30 12月 18 02:28 man
-rw-r--r-- 1 7161 31415 666 12月 18 00:07 README
drwxr-xr-x 28 7161 31415 4096 12月 18 02:28 share
drwxr-xr-x 2 7161 31415 77 12月 18 02:28 support-files [root@localhost mysql]# mkdir data
[root@localhost mysql]# mkdir mysql-files
[root@localhost mysql]# chmod 750 mysql-files
[root@localhost mysql]# chmod 750 data
[root@localhost mysql]# chown -R mysql .
[root@localhost mysql]# chgrp -R mysql .
[root@localhost mysql]# ll
总用量 284
drwxr-xr-x 2 mysql mysql 4096 12月 18 02:28 bin
drwxr-x--- 2 mysql mysql 6 3月 30 02:28 data
drwxr-xr-x 2 mysql mysql 55 12月 18 02:28 docs
drwxr-xr-x 3 mysql mysql 282 12月 18 02:28 include
drwxr-xr-x 6 mysql mysql 201 12月 18 02:28 lib
-rw-r--r-- 1 mysql mysql 276595 12月 18 00:07 LICENSE
drwxr-xr-x 4 mysql mysql 30 12月 18 02:28 man
drwxr-x--- 2 mysql mysql 6 3月 30 13:57 mysql-files
-rw-r--r-- 1 mysql mysql 666 12月 18 00:07 README
drwxr-xr-x 28 mysql mysql 4096 12月 18 02:28 share
drwxr-xr-x 2 mysql mysql 77 12月 18 02:28 support-files # 清除mariadb有关文件
# rpm -qa | grep "mariadb"
mariadb-libs-5.5.68-1.el7.x86_64 # rm -rf /etc/my.cnf
# rm -rf /etc/my.cnf.d/ # 初始化MySQL,会生成一个临时密码
# 此时data目录下会有初始化后的数据
[root@localhost mysql]# bin/mysqld --initialize --user mysql
2022-03-30T06:28:50.697879Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.28-linux-glibc2.12-x86_64/bin/mysqld (mysqld 8.0.28) initializing of server in progress as process 2346
2022-03-30T06:28:50.704665Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-03-30T06:28:51.016806Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-03-30T06:28:51.942504Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ,ai:FtMdM8tX # 设置SSL的RSA,此时会在data存储目录下生成有关文件
[root@localhost mysql]# bin/mysql_ssl_rsa_setup [root@localhost data]# pwd
/usr/local/mysql/data
[root@localhost data]# ll -rw------- 1 mysql mysql 1680 3月 30 14:53 ca-key.pem
-rw-r--r-- 1 mysql mysql 1112 3月 30 14:53 ca.pem
-rw-r--r-- 1 mysql mysql 1112 3月 30 14:53 client-cert.pem
-rw------- 1 mysql mysql 1680 3月 30 14:53 client-key.pem
-rw------- 1 mysql mysql 1680 3月 30 14:53 private_key.pem
-rw-r--r-- 1 mysql mysql 452 3月 30 14:53 public_key.pem
-rw-r--r-- 1 mysql mysql 1112 3月 30 14:53 server-cert.pem
-rw------- 1 mysql mysql 1676 3月 30 14:53 server-key.pem # 将二进制文件的所有权更改为root,数据文件的所有权更改为mysql
[root@localhost mysql]# chown -R root .
[root@localhost mysql]# chown -R mysql data
[root@localhost mysql]# chown -R mysql mysql-files
[root@localhost mysql]# ll
总用量 284
总用量 288
drwxr-xr-x 2 root mysql 4096 12月 18 02:28 bin
drwxr-x--- 6 mysql mysql 4096 3月 30 14:53 data
drwxr-xr-x 2 root mysql 55 12月 18 02:28 docs
drwxr-xr-x 3 root mysql 282 12月 18 02:28 include
drwxr-xr-x 6 root mysql 201 12月 18 02:28 lib
-rw-r--r-- 1 root mysql 276595 12月 18 00:07 LICENSE
drwxr-xr-x 4 root mysql 30 12月 18 02:28 man
drwxr-x--- 2 mysql mysql 6 3月 30 14:52 mysql-files
-rw-r--r-- 1 root mysql 666 12月 18 00:07 README
drwxr-xr-x 28 root mysql 4096 12月 18 02:28 share
drwxr-xr-x 2 root mysql 77 12月 18 02:28 support-files # 将启动脚本复制到init.d中
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld # 将mysql的二进制文件到处到PATH环境变量中
# 临时办法,重启就不能用了
[root@localhost mysql]# export PATH=$PATH:/usr/local/mysql/bin # 永久办法
[root@localhost mysql]# cat >> /etc/profile.d/mysql.sh << "EOF"
#!/bin/bash export PATH=$PATH:/usr/local/mysql/bin
EOF source /etc/profile.d/mysql.sh

安装完毕后将在/usr/local/mysql中获得下图中列出的目录

启动MySQL8

默认没有/etc/my.cnf配置文件

[root@localhost mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
. SUCCESS!
# 使用生成的临时密码登录,并为root用户设置自定义密码
# mysql -hlocalhost -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.28 Copyright (c) 2000, 2022, 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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPass5!';
Query OK, 0 rows affected (0.01 sec) mysql> exit;
Bye # 退出MySQL,并重启MySQL就能使用新密码登录了
[root@localhost mysql]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!

设置开机启动

chkconfig --add mysqld
chkconfig mysqld on
chkconfig mysql --list

日常运行用service或者/etc/init.d/mysqld都可以

[root@localhost mysql]# service mysqld status
ERROR! MySQL is not running
[root@localhost mysql]# service mysqld start
Starting MySQL. SUCCESS!
[root@localhost mysql]# service mysqld status
SUCCESS! MySQL running (1908)
[root@localhost mysql]# service mysqld stop
Shutting down MySQL. SUCCESS!
[root@localhost mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[root@localhost mysql]# service mysqld status
SUCCESS! MySQL running (2083)



二进制安装方式卸载

centos系统安装MySQL8的更多相关文章

  1. Centos系统安装

    Centos系统安装 安装系统前的注意事项 1) 硬件CPU必须支持虚拟化技术,在支持虚拟化的前提下我们还要去把虚拟 的功能打开否则在安装的时候会报错,开启虚拟化需要在BIOS中开启 2)创建虚拟机的 ...

  2. 布衣之路(一):VMware虚拟机+CentOS系统安装

    前言:布衣博主乃苦逼的Java程序猿一枚,虽然工作中不会涉及系统运维,但是开发的项目总还是要部署到服务器做一些负载均衡.系统兼容性测试.系统集成等等骚操作,而这些测试性的操作不可能直接SSH远程运维的 ...

  3. Linux centos系统安装后的基本配置,Linux命令

    一.centos系统安装后的基本配置 .常用软件安装 yum install -y bash-completion vim lrzsz wget expect net-tools nc nmap tr ...

  4. VMware与Centos系统安装

    Linux介绍 1. Linux Linux和windows一样都是操作系统,Linux是开源的.免费的.自由传播的类Unix操作系统软件. 是一个基于POSIX和UNIX的多用户.多任务.支持多线程 ...

  5. VMware与Centos系统安装、重置root密码

    VMware与Centos系统安装   今日任务 .Linux发行版的选择 .vmware创建一个虚拟机(centos) .安装配置centos7 .xshell配置连接虚拟机(centos) 选择性 ...

  6. VMware与Centos系统安装 和重置root密码

    VMware与Centos系统安装   今日任务 1.Linux发行版的选择 2.vmware创建一个虚拟机(centos) 3.安装配置centos7 4.xshell配置连接虚拟机(centos) ...

  7. Docker01 centos系统安装、centos安装docker、docker安装mongoDB

    1 centos系统安装 本博文是基于 centos6.5 的,利用VMware 虚拟机搭建 centos6.5 系统 1.1 centos6.5资源获取 1.2 安装 1.2.1 新建虚拟机 1.2 ...

  8. Linux 及 CentOS系统安装

    VMware与Centos系统安装   今日任务 .Linux发行版的选择 .vmware创建一个虚拟机(centos) .安装配置centos7 .xshell配置连接虚拟机(centos) 选择性 ...

  9. 运维01 VMware与Centos系统安装

    VMware与Centos系统安装   今日任务 1.Linux发行版的选择 2.vmware创建一个虚拟机(centos) 3.安装配置centos7 4.xshell配置连接虚拟机(centos) ...

随机推荐

  1. 如何用Python实现配置热加载?

    背景 由于最近工作需求,需要在已有项目添加一个新功能,实现配置热加载的功能.所谓的配置热加载,也就是说当服务收到配置更新消息之后,我们不用重启服务就可以使用最新的配置去执行任务. 如何实现 下面我分别 ...

  2. MySQL--排序检索数据(ORDER BY)

    检索出的数据并不是以纯粹的随机顺序显示的.如果不排序,数据一般将以它在底层表中出现的顺序显示.这可以是数据最初添加到表中的顺序.但是,如果数据后来进行过更新或删除,则此顺序将会受到MySQL重用回收存 ...

  3. input 输入框背景色设置为透明

  4. 后端Python3+Flask结合Socket.io配合前端Vue2.0实现简单全双工在线客服系统

    原文转载自「刘悦的技术博客」https://v3u.cn/a_id_158 在之前的一篇文章中:为美多商城(Django2.0.4)添加基于websocket的实时通信,主动推送,聊天室及客服系统,详 ...

  5. 0202年,您真的需要Thrift这样一个RPC微服务框架来拯救一下传统HTTP接口(api)了

    原文转载自「刘悦的技术博客」https://v3u.cn/a_id_104 目前市面上类似Django的drf框架基于json的http接口解决方案大行其道,人们也热衷于在接口不多.系统与系统交互较少 ...

  6. 一寸宕机一寸血,十万容器十万兵|Win10/Mac系统下基于Kubernetes(k8s)搭建Gunicorn+Flask高可用Web集群

    原文转载自「刘悦的技术博客」https://v3u.cn/a_id_185 2021年,君不言容器技术则已,欲言容器则必称Docker,毫无疑问,它是当今最流行的容器技术之一,但是当我们面对海量的镜像 ...

  7. 6.17 NOI 模拟

    \(T1\ crime\) 计算几何\(+\)最短路,我的写法很麻烦 比较无脑,直接扫一遍判断能否连接即可,需要特别判断对角线的情况 #include<bits/stdc++.h> #de ...

  8. C++11实现可变参数泛型抽象工厂

  9. Spring源码 02 项目搭建

    参考源 https://www.bilibili.com/video/BV1tR4y1F75R?spm_id_from=333.337.search-card.all.click https://ww ...

  10. 认识Vue扩展插件

    众所周知,在 Vue 开发中,实现一个功能可以有很多种方式可以选择,这依赖于 Vue 强大的功能(指令.混合.过滤.插件等),本文介绍一下插件的开发使用. Vue 插件 插件通常用来为 Vue 添加全 ...