oneinstack 配置MySQL远程连接

 

1. 云主机安全组端口开放3306端口

 

2. 打开iptables 3306端口

 

PS: 只有开启了iptables才需要此步骤!
如果您的操作系统为CentOS系列:

 

iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
service iptables save #保存iptables规则

如果您的操作系统为Ubuntu/Debian系列:

 

iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
iptables-save > /etc/iptables.up.rules #保存iptables规则

3. 数据库授权

 

注意⚠️:远程连接新建一个帐号(帐号名不能为root)。
如:添加一个用户名为db_user,密码为db_pass,授权为% (%表示所有IP能连接)对db_name数据库所有权限,命令如下:

 

1)MySQL8.0版本

 

# mysql -uroot -p
MySQL [(none)]> create user wxx@'%' identified by 'ok'; #创建用户
MySQL [(none)]> grant all privileges on *.* to wxx@'%' with grant option; #授权
MySQL [(none)]> exit; #退出数据库控制台,特别注意有分号

 

2)其余MySQL版本

 

# mysql -uroot -p
MySQL [(none)]> grant all privileges on *.* to wxx@'%' identified by 'ok'; #授权语句,特别注意有分号
MySQL [(none)]> flush privileges;
MySQL [(none)]> exit; #退出数据库控制台,特别注意有分号

 

 

授权用户名为wxx 密码 ok 访问所有的数据库

grant all privileges on *.* to wxx@'%' identified by 'ok';

*.* 代表所有的库都可以访问

 

posted @ 2020-04-15 12:01  Sea_wxx  阅读(355)  评论(0编辑  收藏  举报