2022年4月 centos7.6安装mysql 8.0.29 开启远程连接、允许简单密码

1.centos7.6 最小化安装

网上一大堆教程,怎么装就不说了。

1.1 必备设置

#先安装一些基本的东西
yum install -y wget vim net-tools

#临时关闭SELINUX
setenforce 0
#vim打开后修改SELINUX=disabled 永久关闭selinux
vim /etc/selinux/config

#关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service


替换成国内镜像源,网上教程一堆,也可以直接如下操作

vim /etc/yum.repos.d/CentOS-Base.repo
#打开文件后 复制下面后输入:wq 退出保存
#开始
[base]
name=CentOS-7- Base
baseurl=http://ftp.sjtu.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey= http://ftp.sjtu.edu.cn/centos/RPM-GPG-KEY-CentOS-7

[update]
name=CentOS-7 - Updates
baseurl= http://ftp.sjtu.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey= http://ftp.sjtu.edu.cn/centos/RPM-GPG-KEY-CentOS-7

[extras]
name=CentOS-7 - Extras
baseurl= http://ftp.sjtu.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey= http://ftp.sjtu.edu.cn/centos/RPM-GPG-KEY-CentOS-7

[centosplus]
name=CentOS-7 - Plus
baseurl= http://ftp.sjtu.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey= http://ftp.sjtu.edu.cn/centos/RPM-GPG-KEY-CentOS-7
#结束
更新缓存
yum makecache

2.安装mysql

#安装官方mysql储存库
wget https://dev.mysql.com/get/mysql80-community-release-el7-6.noarch.rpm
yum install -y mysql80-community-release-el7-6.noarch.rpm
#安装认证文件 否则之后安装时会报错
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
#安装mysql
yum install mysql-community-server -y

2.1 使用mysql_native_password加密方式

否则客户端登录可能会报:Public Key Retrieval is not allowed

vim /etc/my.cnf
#default-authentication-plugin=mysql_native_password 前面的井号去掉,取消注释

#启动mysql
systemctl start mysqld
netstat -ntlup|grep 3306

2.2 登录mysql 并修改为简单密码

本地测试不需要那么复杂的密码

#查询mysql初始密码
grep 'temporary password' /var/log/mysqld.log
2022-04-27T04:29:33.877768Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 0sg(sJ8Tiljs
#-p后面填写的是上面命令查到的密码(特殊字符需要转义)
mysql -u root -p0sg\(sJ8Tiljs
#需要先修改一次复杂密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Well123,';
#持久化设置密码等级、长度
set persist validate_password.policy=0;
set persist validate_password.length=4;

#修改为简单密码
alter user 'root'@'localhost' identified with mysql_native_password by '123456';
flush privileges;

#允许远程登录root
update mysql.user set host='%' where user='root';
flush privileges;
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值