注:全文命令行用蓝色字体标注,报错异常用红色字体标注
回车开始下载
tar -xvf mysql-8.0.13-1.el7.x86_64.rpm-bundle.tar
使用 rpm -vih XX 命令安装:
依次顺序是:
rpm -vih mysql-community-common-8.0.13-1.el7.x86_64.rpm
rpm -vih mysql-community-libs-8.0.13-1.el7.x86_64.rpm
rpm -vih mysql-community-libs-compat-8.0.13-1.el7.x86_64.rpm
rpm -vih mysql-community-client-8.0.13-1.el7.x86_64.rpm
rpm -vih mysql-community-embedded-compat-8.0.13-1.el7.x86_64.rpm
rpm -vih mysql-community-server-8.0.13-1.el7.x86_64.rpm
期间安装mysql-community-libs-8.0.13-1.el7.x86_64.rpm的时候报错
mariadb-libs is obsoleted by mysql-community-libs-8.0.13-1.el7.x86_64
原因是cenos 7默认的是mariadb数据库,所以要先卸载mariadb.
卸载步骤是:
输入命令 rpm -qa|grep mariadb 找到mariadb数据库
输入命令 rpm -e mariadb-libs-5.5.41-2.el7_0.x86_64
报错:Failed dependencies:
libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
由于存在依赖关系,强制卸载:
rpm -e --nodeps mariadb-libs-5.5.41-2.el7_0.x86_64
卸载成功,再次输入 rpm -qa|grep mariadb
已经找不到了。
注:安装期间如果出现类似报错:
error: Failed dependencies:
mysql-community-client(x86-64) >= 8.0.13 is needed by mysql-community-server-8.0.13-1.el7.x86_64
说明安装顺序不对,调整安装顺序即可
输入命令:systemctl status mysqld.service
如果显示不是running,则还需输入命令
systemctl start mysqld.service 来启动服务
使用临时密码登录
输入命令 grep "password" /var/log/mysqld.log 查看临时密码
如图我这里的临时密码是ykon4xvl?swQ
登录:
mysql -uroot -pykon4xvl?swQ
登录成功,修改密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'beijing';
报错:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
这是因为设置的密码不符合mysql8的规范
解决办法调整MySQL密码验证规则,修改 policy 和 length 的值
set global validate_password.policy=0;
set global validate_password.length=1;
再次尝试修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'beijing';
修改成功