CentOS下安装MySQL数据库

14. June 2017 Linux 0

下载rpm格式文件,然后根据官网链接安装即可。https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/。

在CentOS安装好Mysql数据库修改好密码以后,假设需要设置MySQL可远程链接

mysql -u root -p 

mysql>use mysql; 

mysql>update user set host = '%' where user = 'root'; 

mysql>select host, user from user;

FLUSH PRIVILEGES
firewall-cmd --zone=public --add-port=3306/tcp --permanent 添加    (--permanent永久生效,没有此参数重启后失效)
firewall-cmd --reload 重新载入
firewall-cmd --zone= public --query-port=3306/tcp 查看
firewall-cmd --zone= public --remove-port=3306/tcp --permanent 删除

设置好后,需要修改CentOS防火墙设置,允许3306端口。

systemctl stop firewalld.service 关闭防火墙

systemctl start  firewalld.service 开启防火墙

systemctl disable firewalld.service 禁止开机启动

systemctl status firewalld 查看防火墙运行状态

.配置firewalld-cmd

查看版本: firewall-cmd –version
查看帮助: firewall-cmd –help
显示状态: firewall-cmd –state
查看所有打开的端口: firewall-cmd –zone=public –list-ports
更新防火墙规则: firewall-cmd –reload
查看区域信息:  firewall-cmd –get-active-zones
查看指定接口所属区域: firewall-cmd –get-zone-of-interface=eth0
拒绝所有包:firewall-cmd –panic-on
取消拒绝状态: firewall-cmd –panic-off
查看是否拒绝: firewall-cmd –query-panic