一.安装MySQL

安装mysql 
yum install -y mysql-server
设置开机自动启动
systemctl enable mysqld.service
检查开机自动启动是否设置成功
systemctl list-unit-files|grep mysqld

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

打开MySQL
mysql -u root -p

修改初始密码
mysqladmin -uroot password 'YourPassword' #注意位数和种类至少大写+小写+符号+数字
--or
ALTER USER 'root'@'localhost' IDENTIFIED BY 'YourPassword';

二、允许外部访问MySQL



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

2.赋予任何主机访问权限
 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;
 FLUSH PRIVILEGES
--出现You are not allowed to create a user with GRANT  使用以下命令
 update user set host='%' where user='root'; 

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
posted on 2022-11-04 17:45  Sleepy-Person  阅读(37)  评论(0编辑  收藏  举报