电光石火-穿越时空电光石火-穿越时空


Centos7安装Mysql8教程

yum方式安装

1.由于centOS7中默认安装了MariaDB,需要先进行卸载

rpm -qa | grep -i mariadb
rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64

查询下本机mysql是否卸载干净,若有残留也需要卸载

rpm -qa | grep mysql

2.下载MySQL仓库并安装

wget https://repo.mysql.com//mysql80-community-release-el7-7.noarch.rpm
yum -y install mysql80-community-release-el7-7.noarch.rpm

3.安装MySQL数据库

yum -y install mysql-community-server

4.开启mysql服务

systemctl start mysqld.service

5.查看mysql默认密码并登陆

cat /var/log/mysqld.log | grep password

第一次进去提示需要修改密码ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

alter user 'root'@'localhost' identified by 'yourpassword';
flush privileges;

修改初始密码(若想改为弱密码)

SHOW variables LIKE 'validate_password%';

注:如果遇到需要强密码的报错,此时先修改密码为强密码,便可以继续进行修改密码验证策略操作。将密码验证策略改为LOW,密码长度4位以上

set global validate_password.policy=0; #有的MySQL版本为validate_password_policy,此处请以上一步查询到的字段名称为准
set global validate_password.length=4; #重启MySQL后失效

此时再进行修改密码操作,可以修改为弱密码了

ALTER USER 'root'@'localhost' IDENTIFIED BY 'your password';

6.设置远程连接(前提:关闭防火墙或开放3306端口)
在实际工作中,经常会远程连接mysql数据库,需要设置允许远程连接。

在mysql数据库的user表中查看host,默认只允许localhost访问,只需将localhost改为%允许任意地址访问即可

use mysql;
update user set host = '%' where user = 'root';
flush privileges; # 刷新权限 权限更新后刷新才会起作用

注:如果使用客户端连接提示了plugin caching_sha2_password错误,这是因为MySQL8.0的密码策略默认为caching_sha2_password(MySQL5.7无此问题)

update user set plugin = 'mysql_native_password' where user = 'root';
flush privileges; # 刷新权限 权限更新后刷新才会起作用

本博客所有文章如无特别注明均为原创。作者:似水的流年
版权所有:《电光石火-穿越时空》 => Centos7安装Mysql8教程
本文地址:http://www.ilkhome.cn/index.php/archives/880/
欢迎转载!复制或转载请以超链接形式注明,文章为 似水的流年 原创,并注明原文地址 Centos7安装Mysql8教程,谢谢。

评论