新装的CentOS8,安装最新版MySQL8.0.30

** 新装的CentOS8
1.配置网络服务
cd /etc/sysconfig/network-scripts
vi ifcfg-ens160 修改配置项:ONBOOT=yes【最后一行】
2.重启网络服务
nmcli networking off
nmcli networking on
如果启动不了,提示Error:NetworkManager is not running,则需要手动启动NetworkManager
systemctl start NetworkManager
现在就可以通过ip add查看ip地址了,能连上Xshenll了
3.配置下载源
cd /etc/yum.repos.d
创建备份:mkdir back mv CentOS-* back
下载阿里云元数据文件:wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
建立新元数据缓存:yum makecache
4.安装
wget https://repo.mysql.com/mysql80-community-release-el8-4.noarch.rpm
yum -y install mysql80-community-release-el8-4.noarch.rpm
yum -y install mysql-community-server
禁用CentOS自带:sudo yum module disable mysql
5.启动服务
启动mysql服务:systemctl start mysqld.service
查看是否启动mysql服务:systemctl status mysqld.service
6.修改密码
查看mysql初始密码:grep "password" /var/log/mysqld.log
进入mysql:mysql -u root -p
**密码先修改一个符合规则的复杂的密码,再修改配置项,然后再改成想要的密码(大小写字母+数字+符号)
修改密码:alter user user() identified by "newPassword"
如果提示密码强度过低
set global validate_password.policy=0; # 密码强度设为最低等级
set global validate_password.length=1; # 密码允许最小长度为4,也可以是1
flush privileges; # 更新授权表,生效
7.设置防火墙
关闭防火墙:systemctl stop firewalld
查看防火墙是否关闭:systemctl status firewalld
禁用防火墙:systemctl disable firewalld
查看Linux是否安装iptables:systemctl status iptables.service
【如未安装执行:yum install -y iptables】
【安装iptables-service: yum -y install iptables-services】
修改文件:sudo vi /etc/sysconfig/iptables
不要将如下语句添加到文件末尾,应该添加到22端口这条规则的下面
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT # 仅安装mysql,这条不必执行
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
保存配置:service iptables save
重启防火墙:systemctl restart iptables.service
设置开机启动:systemctl enable iptables.service
8.修改允许的连接人
最后进入mysql配置远程访问权限(远程登录的用户名为root,密码为"root")
控制台执行语句1-3:
create user 'root'@'%' identified by '密码';
如果语句执行失败,那就drop root,重新create就行
grant all on *.* to 'root'@'%';
alter user 'root'@'%' identified with mysql_native_password by '密码';
控制台执行语句4: FLUSH PRIVILEGES;