Bootstrap

CentOS 7.6 安装 MySQL 8.0.28

删除 Mariadb,防止与 MySQL 冲突

查询是否有 mariadb

rpm -qa | grep mariadb

强制删除 mariadb

rpm -e --nodeps mariadb-libs

升级

yum -y updateyum -y upgrade

区别:

yum -y upgrade只升级所有包和系统版本,不会改变内核、软件设置和系统设置

yum -y update升级所有包、系统版本和内核,改变软件设置和系统设置

yum install -y unzip zip

下载

mysql_8.0.28_x64 下载地址

在 Windows 系统上解压,删除不需要的包;重新压缩再上传到 Linux 服务器上(/root);(留下的文件如下图)
保留文件
(删除的文件:develembeddedcompattest
解压

unzip mysql-8.0.28-1.el7.x86_64.rpm-bundle.zip

cd mysql-8.0.28-1.el7.x86_64.rpm-bundle

安装

注:包有依赖关系,要按顺序安装

rpm -ivh mysql-community-common-8.0.28-1.el7.x86_64.rpm

rpm -ivh mysql-community-client-plugins-8.0.28-1.el7.x86_64.rpm

rpm -ivh mysql-community-libs-8.0.28-1.el7.x86_64.rpm

报错解决办法:

yum remove mysql-libs

rpm -ivh mysql-community-client-8.0.28-1.el7.x86_64.rpm

rpm -ivh mysql-community-icu-data-files-8.0.28-1.el7.x86_64.rpm

rpm -ivh mysql-community-server-8.0.28-1.el7.x86_64.rpm --nodeps --force

初始化

mysqld --initialize --consloe

如果遇到如下错误:

mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

解决方法:

yum install -y libaio.so.1

yum install -y libaio

授权

对 mysql 用户 mysql 组 授权

chown -R mysql:mysql /var/lib/mysql/

启动服务

systemctl start mysqld

如果遇到如下错误:

Job for mysqld.service failed because the control process exited with error code. See “systemctl status mysqld.service” and “journalctl -xe” for details.

解决方法:

rm -rf /var/lib/mysql/*

获取临时密码

cat /var/log/mysqld.log | grep root@localhost

连接 MySQL

mysql -u root -p

输入临时密码

修改密码

alter user user() identified by '123qwe!@#';

密码至少包含8个字符并且至少包含一个大写字母、一个小写字母、一个数字和一个特殊字符。

重新连接,修改配置

mysql -u root -p

输入临时密码:123qwe!@#

use mysql;

select host from user where user='root';

update user set host = '%' where user ='root';

flush privileges;

更改加密方式

ALTER USER 'root'@'%' IDENTIFIED BY '123qwe!@#' PASSWORD EXPIRE NEVER;

更新用户密码

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123qwe!@#';

刷新权限

FLUSH PRIVILEGES;

— 完成 —

;