使用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. 2m高分辨率土地利用分类数据

    数据下载链接:百度云下载链接 土地利用数据是在根据影像光谱特征,结合野外实测资料,同时参照有关地理图件,对地物的几何形状,颜色特征.纹理特征和空间分布情况进行分析,建立统一解译标志的基础之上,依据多源 ...

  2. 异构图神经网络笔记-Heterogeneous Graph Neural Network(KDD19)

    自己讲论文做的异构图神经网络的ppt.再转变成博客有点麻烦,所以做成图片笔记. 论文链接:https://arxiv.org/abs/1903.07293

  3. Python迷宫生成器

    作为一项古老的智力游戏,千百年来迷宫都散发着迷人的魅力.但是,手工设计迷宫费时又耗(脑)力,于是,我们有必要制作一个程序:迷宫生成器-- 好吧,我编不下去了.但是,从上面的文字中,我们可以看出,我们此 ...

  4. IO多路复用epoll

    0 why: 问题来源 0.1 网络编程流程 //创建socket int s = socket(AF_INET, SOCK_STREAM, 0); //绑定IP地址和端口号port bind(s, ...

  5. java-数据输入,分支结构

    数据输入 1.Scanner使用的基本步骤" 导包:import java.util.Scanner;(导包的动作必须出现在类定义的上边) 创建对象:Scanner sc = new Sca ...

  6. 05 MySQL_主键约束

    主键约束 主键: 用于表示数据唯一性的字段称为主键: 约束:就是对表字段添加限制条件 主键约束:保证主键字段的值唯一且非空: - 格式 : create table t1(id int primary ...

  7. mysql5.7通过文件zip方式安装-九五小庞

    为什么通过zip的方式进行安装 电脑上已安装过mysql数据库,想要再安装一个. 1.下载mysql安装包 直接找到mysql官网,在官网上下载zip安装包. https://downloads.my ...

  8. TCP通信的客户端代码实现和TCP通信的服务器代码实现

    TCP通信的客户端代码实现 package com.yang.Test.ServerStudy; import java.io.*; import java.net.Socket; /** * TCP ...

  9. YII学习总结6(模板替换和“拼合”)

    controller\helloController.php<?php namespace app\controllers; use yii\web\Controller; class hell ...

  10. 精心整理16条MySQL使用规范,减少80%问题,推荐分享给团队

    上篇文章介绍了如何创建合适的MySQL索引,今天再一块学一下如何更规范.更合理的使用MySQL? 合理规范的使用MySQL,可以大大减少开发工作量和线上问题,并提升SQL查询性能. 我精心总结了这16 ...