头图
  1. 从官网下载MySQL8安装包(https://dev.mysql.com/downloa...
    image.png
  2. 将下载好的安装包上传至服务器上
    image.png
  3. 删除原有的mysql和mariadb
rpm -qa|grep mysql
rpm -qa|grep mariadb

image.png

rpm -e --nodeps mysql-community-libs
rpm -e --nodeps mysql-community-server
rpm -e --nodeps mysql-community-client
rpm -e --nodeps mysql-community-common
rpm -e --nodeps mysql-community-client-plugins
rpm -e --nodeps mariadb

image.png

  1. 解压MySQL安装包
tar -xvf mysql-8.0.27-1.el7.x86_64.rpm-bundle.tar

解压后生成以下文件
image.png

  1. 逐个安装rpm包,注意安装顺序
rpm -ivh mysql-community-common-8.0.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.27-1.el7.x86_64.rpm
  1. 查看服务状态
systemctl status mysqld

image.png

此时MySQL服务尚未启动,先进行数据库初始化操作,输入以下命令:

mysqld --initialize --console

再授权目录:

chown -R mysql:mysql /var/lib/mysql/
  1. 启动MySQL服务
systemctl start mysqld

查看此时MySQL服务的状态:

systemctl status mysqld

image.png

MySQL已启动!

  1. 修改MySQL登录

获取临时密码

grep 'temporary password' /var/log/mysqld.log

image.png

复制临时密码,然后登录MySQL复制临时密码,然后登录MySQL

mysql -uroot -p

修改密码:

ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';

刷新权限:

flush privileges;

此时就可以用新密码登录了。


强力小磊哥
79 声望6 粉丝

翻过一座山,就高过一座山