一.下载
#下载mysql安装包以及依赖的文件
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-community-server-8.0.15-1.el7.x86_64.rpm wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-community-client-8.0.15-1.el7.x86_64.rpm wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-community-devel-8.0.15-1.el7.x86_64.rpm wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-community-common-8.0.15-1.el7.x86_64.rpm wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-community-libs-compat-8.0.15-1.el7.x86_64.rpm wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-community-libs-8.0.15-1.el7.x86_64.rpm
二.安装
首先
#卸载Centos7自带的mariadb,不然安装mysql的时候会有冲突
yum remove mariadb-libs -y
其次,安装
#注意:安装顺序必须按照以下顺序,因为这些包之间也有依赖关系
rpm -ivh mysql-community-common-8.0.15-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-8.0.15-1.el7.x86_64.rpm rpm -ivh mysql-community-devel-8.0.15-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-compat-8.0.15-1.el7.x86_64.rpm rpm -ivh mysql-community-client-8.0.15-1.el7.x86_64.rpm rpm -ivh mysql-community-server-8.0.15-1.el7.x86_64.rpm
三.重启MySQL
#启动mysql
systemctl start mysqld
#找到随机密码
grep "temporary password" /var/log/mysqld.log
#登陆mysql
mysql –u root –p
输入获得的随机密码
四.修改密码
#在MySQL中‘;’代表语句输入结束
(1)查看MySQL密码策略
show variables like '%validate%';
(2)设置简单密码
注:global配置全局 相当于更改配置文件my.cnf
set global validate_password.policy=0;密码安全等级 0代表最弱 set global validate_password.mixed_case_count=0;大小写字母的最少个数 set global validate_password.number_count=0; 密码中数字的最少个数 set global validate_password.special_char_count=0; 特殊字符的最少个数 flush privileges;
(3)修改密码
LTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';
五.重启MySQL
重启MySQL服务
systemctl restart mysqld;
#登陆mysql
mysql –u root –p
输入你修改后的密码 ,检验是否操作成功。