使用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. D2C小练习

    前端智能化现状及未来展望 简介 DEsign: Sketch,Photoshop ,Figma 起源:微软2017年, Design to code code: 前端 核心原理 design----& ...

  2. 创建多线程程序的第一种方式_创建Thread类的子类

    创建多线程程序的第一种方式:创建Thread类的子类java.lang.Thread类:是描述线程的类,我们想要实现多线程程序,就必须继承Thread类 实现步骤: 1.创建一个Thread类的子类 ...

  3. 【cartographer_ros】六: 发布和订阅路标landmark信息

    上一节介绍了陀螺仪Imu传感数据的订阅和发布. 本节会介绍路标Landmark数据的发布和订阅.Landmark在cartographer中作为定位的修正补充,避免定位丢失. 这里着重解释一下Land ...

  4. Java开发学习(十一)----基于注解开发bean作用范围与生命周期管理

    一.注解开发bean作用范围与生命周期管理 前面使用注解已经完成了bean的管理,接下来将通过配置实现的内容都换成对应的注解实现,包含两部分内容:bean作用范围和bean生命周期. 1.1 环境准备 ...

  5. ooday02构造方法_this_引用类型数组

    笔记: 构造方法:构造函数.构造器.构建器---------复用给成员变量赋初值代码 作用:给成员变量赋初始值 与类同名,没有返回值类型(连void都没有) 在创建(new)对象时被自动调用 若自己不 ...

  6. RabbitMQ细说之开篇

    前言 关于消息中间件的应用场景,小伙伴们应该都耳熟能详了吧,比如经常提到的削峰填谷.分布式事务.异步业务处理.大数据分析等等,分布式消息队列成为其中比较关键的桥梁,也就意味着小伙伴们得掌握相关技能:当 ...

  7. CF1656D K-good

    题意: 给定一个整数 \(n\),请找出一个大于等于 \(2\) 的整数 \(k\),使得 \(n\) 可以表示成 \(k\) 个除以 \(k\) 的余数互不相同的数之和. 注意\(k\)个除以 \( ...

  8. springmvc源码笔记-RequestMappingHandlerMapping

    下图是springmvc的执行流程 图片来源:https://www.jianshu.com/p/8a20c547e245 DispatcherServlet根据url定位到Controller和方法 ...

  9. AI全流程开发难题破解之钥

    摘要:通过对ModelArts.盘古大模型.ModelBox产品技术的解读,帮助开发者更好的了解AI开发生产线. 本文分享自华为云社区<[大厂内参]第16期:华为云AI开发生产线,破解AI全流程 ...

  10. 使用python3.7和opencv4.1来实现人脸识别和人脸特征比对以及模型训练

    原文转载自「刘悦的技术博客」https://v3u.cn/a_id_126 OpenCV4.1已经发布将近一年了,其人脸识别速度和性能有了一定的提高,这里我们使用opencv来做一个实时活体面部识别的 ...