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;