[root@localhost ~]# wget https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm
[root@localhost ~]# rpm -ivh mysql80-community-release-el8-1.noarch.rpm
[root@localhost ~]# yum install mysql-server
[root@localhost ~]# systemctl list-unit-files|grep mysqld
mysqld.service disabled
mysqld@.service disabled
[root@localhost ~]# systemctl enable mysqld.service #设置开机启动
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@localhost ~]# systemctl list-unit-files|grep mysqld
mysqld.service enabled
mysqld@.service disabled
[root@localhost ~]# ps -ef|grep mysql # 查看是否启动MySQL服务
root 4311 32702 0 21:07 pts/4 00:00:00 grep --color=auto mysql
[root@localhost ~]# systemctl start mysqld.service #启动服务
alter user root@localhost identified by ‘1234‘;
flush privileges; # 刷新MySQL的系统权限
quit;
# 开放3306端口
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
?
# 重启防火墙
[root@localhost ~]# firewall-cmd --reload
?
# 查看防火墙状态,3306端口已开
[root@localhost ~]# firewall-cmd --list-all
# 允许建立远程连接
create user ‘root‘@‘%‘ identified with mysql_native_password by ‘密码‘;
grant all privileges on *.* to ‘root‘@‘%‘ with grant option;
flush privileges;
原文:https://www.cnblogs.com/Leviathangk/p/14083438.html