1.下载
链接: https://dev.mysql.com/downloads/mysql/
centos的选择红帽版本就行
2.解压
tar -xvf mysql-8.3.0-1.el7.x86_64.rpm-bundle.tar
4.卸载旧mysql
rpm -qa | grep -i mysql
rpm -qa | grep -i mariadb
# 强制卸载
rpm -e --nodeps xxx
保证卸载完成
3.安装
#1.安装一些依赖,在mysql安装过程如果存在报错,根据报错信息安装对应的依赖即可
yum -y install net-tools perl
# 安装
rpm -ivh mysql-community-common-8.3.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.3.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.3.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.3.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.3.0-1.el7.x86_64.rpm
# 启动
systemctl start mysqld
# 开机自启
systemctl enable mysqld
# 停止
systemctl stop mysqld
# 重启
systemctl restart mysqld
# 查看状态
systemctl status mysqld
4.修改密码
# 初始化密码
mysqld --initialize --user=mysql
# 查看密码
cat /var/log/mysqld.log
登录后修改密码
set global validate_password.policy=0; # 密码强度
set global validate_password.length=1; # 密码长度
set global validate_password.check_user_name=0; #检查是否与用户名同名,如果开启的话,禁止设置同名密码,例如 root用户禁止设置密码为root
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';# 修改密码
flush privileges;
# 创建远程登录用户
CREATE USER 'root'@'%' IDENTIFIED BY 'root';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
flush privileges;
修改的时候添加上 'mysql_native_password ’ ,避免远程登录的时候报错