安装Yum Repository
[root@localhost ~]# wget https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm
使用rpm来安装MySQL
[root@localhost ~]# rpm -ivh mysql80-community-release-el8-1.noarch.rpm
使用yum安装mysql服务
[root@localhost ~]# yum install mysql-server
检查是否已经设置为开机启动MySQL服务
[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 #启动服务
安装成功之后进行msyql的配置
通过 cat /var/log/mysqld.log | grep password 命令查看数据库的密码
通过 mysql -uroot -p 进入数据库登陆界面,输入刚刚查到的密码,进行数据库的登陆,复制粘贴就行,MySQL 的登陆密码也是不显示的
通过 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码'; 命令来修改密码
通过 exit; 命令退出 MySQL,然后通过新密码(root)再次登陆
通过以下命令,进行远程访问的授权
create user 'root'@'%' identified with mysql_native_password by '你的密码';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
输入exit退出,打开防火墙开放3306端口
如果没有开启防火墙,则输入:systemctl start firewalld 开启
输入下面命令,开放3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload