Centos7安装MySQL8

Centos7安装MySQL8

通过配置yum安装MySQL

yum源的配置是通过清华源配置的

https://mirrors.tuna.tsinghua.edu.cn/

环境介绍

操作系统:Centos7.8

MySQL版本:8.0.36-1

安装前准备

  1. 卸载MariaDB

    shell 复制代码
    # 查看是否安装mariadb
    rpm -qa|grep mariadb
    
    # 卸载
    rpm -e --nodeps 文件名
    
    # 检查是否卸载干净
    rpm -qa|grep mariadb
  2. 检查依赖

    shell 复制代码
    # 查看是否安装libaio
    rpm -qa|grep libaio
    
    # 如果没有安装则执行
    yum -y install libaio //安装libaio 
    
    # 查看是否安装numactl
    rpm -qa|grep numactl
    
    # 如果没有安装则执行
    yum -y install numactl //安装numactl 	

安装MySQL

创建yum源的过程:

https://mirrors.tuna.tsinghua.edu.cn/


即:

shell 复制代码
# 执行如下命令创建yum源文件
vim /etc/yum.repos.d/mysql-community.repo
# 将下面内容赋值到上面这个文档中
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-connectors-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

[mysql-tools-community]
name=MySQL Tools Community
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

[mysql-8.0-community]
name=MySQL 8.0 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

保存过后到/etc/yum.repos.d/ 下面会发下多了上面创建的mysql-community.repo yum源文件

使用yum安装MySQL

shell 复制代码
# 执行如下查看msyql版本 (--showduplicates 是查看对应版本)
yum search mysql-community-server --showduplicates
# 安装对应版本的mysql  (--nogpgcheck 是跳过gpg检查)
yum -y install mysql-community-server-8.0.36-1.el7.x86_64 --nogpgcheck

启动MySQL并修改初始密码

shell 复制代码
# 启动
systemctl start mysqld
# 查看mysql服务启动是否成功
systemctl status mysqld
shell 复制代码
#查看初始密码
grep 'temporary password' /var/log/mysqld.log

# 登录mysql,一定要注意:-p和'密码'之间是没有空格的
mysql -u root -p'x*qrf.jvo9mS'

#修改root初始密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root@123';

开放 root 账户远程登录

shell 复制代码
#重新登录
mysql -u root -p'Root@123'
# 1、进入数据库
use mysql;
# 2、修改user表
update user set host='%' where user='root';
# 重载授权表
FLUSH PRIVILEGES;
# 退出
exit

# 重启
systemctl restart mysqld

总结

至此安装完毕!

相关推荐
流烟默7 分钟前
MySQL索引调优之索引顺序必须和字段顺序一致吗?
mysql·索引调优
我是Superman丶1 小时前
【优化】Mysql指定索引查询或忽略某个索引
数据库·mysql
LL_break1 小时前
Mysql数据库
java·数据库·mysql
星光一影5 小时前
【OA办公系统】神点企业OA办公助手/全开源
mysql·nginx·开源·php·源代码管理
华仔啊6 小时前
千万级大表如何新增字段?别再直接 ALTER 了
后端·mysql
Maple_land6 小时前
Linux进程第八讲——进程状态全景解析(二):从阻塞到消亡的完整生命周期
linux·运维·服务器·c++·centos
W.Buffer8 小时前
通用:MySQL主库BinaryLog样例解析(ROW格式)
android·mysql·adb
W.Buffer8 小时前
通用:MySQL-InnoDB事务及ACID特性
数据库·mysql