Centos安装MySql


一、安装MySql
1.查看Centos系统版本
cat /etc/centos-release

2.查看当前目录路径
pwd

3.安装wget
yum install -y wget

4.下载MySQL的RPM安装包
wget https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm

5.使用RPM安装
rpm -ivh mysql80-community-release-el8-1.noarch.rpm

6.使用YUM安装MySQL服务
yum install -y mysql-server

7.设置开机自动启动
systemctl enable mysqld.service

8.检查开机自动启动是否设置成功
systemctl list-unit-files|grep mysqld

9.启动MySQL服务并检查服务是否开启
systemctl start mysqld.service
ps -ef|grep mysql

10.查看开放的端口(MySQL需要开放3306端口)
netstat -tlunp

11.打开MySQL
mysql -u root -p

12.修改初始密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';#注意位数和种类至少大+写+小写+符号+数字

二、允许外部访问MySQL

1.修改MySQL数据库下的user中host值
mysql -u root -p
use mysql;
update user set host='%' where user='root';

2.赋予任何主机访问权限
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES

3.开启防火墙
systemctl start firewalld

4.添加3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent

5.重新加载防火墙端口
firewall-cmd --reload

6.查看防火墙开启的端口
firewall-cmd --zone=public --list-ports

 

注:这里防火墙添加3306端口后需要重启防火墙一下 (以及,阿里云服务器的话,需要再自行上阿里云控制台去添加3306端口)

firewall-cmd --reload

 

感谢:

https://www.jianshu.com/p/a355bbf11d07

https://blog.csdn.net/weixin_42634193/article/details/86077651

https://blog.csdn.net/weiyangdong/article/details/79540217

https://blog.csdn.net/cheers_bin/article/details/108191308

posted @ 2021-06-12 10:43  蜗牛的礼物  阅读(210)  评论(0编辑  收藏  举报