linux下mysql允许远程连接
时间:2018年09月13日 人气:...

1.查看linux防火墙是否开放3306端口

执行iptables -nL --line-number 

这里显示DROP代表防火墙阻止了3306端口。

2.添加防火墙例外

执行vim /etc/sysconfig/iptables 

3.重启防火墙

执行service iptables restart 
查看是否变为ACCEPT

4.创建远程连接用户并授权

mysql> select Host,User,Password from mysql.user;
+----------------+------------------+-------------------------------------------+| Host           | User             | Password                                  |
+----------------+------------------+-------------------------------------------+| localhost      | root             | *836E233974EBE6EA32F95F890A91363F8427F78B |
| iz94926clkiz   | root             | *836E233974EBE6EA32F95F890A91363F8427F78B |
| 127.0.0.1      | root             | *836E233974EBE6EA32F95F890A91363F8427F78B |
| ::1            | root             | *836E233974EBE6EA32F95F890A91363F8427F78B || localhost      | debian-sys-maint | *1460ED3535ABDBB887F9E5F57F40A2354610CDF3 |
+----------------+------------------+-------------------------------------------+rows in set (0.00 sec)1234567891011

创建用户

create user test identified by '123456';1
+----------------+------------------+-------------------------------------------+| Host           | User             | Password                                  |
+----------------+------------------+-------------------------------------------+| localhost      | root             | *836E283974EBE6EA32F95F890A91363F8427F78B |
| iz949s6clkiz   | root             | *836E283974EBE6EA32F95F890A91363F8427F78B |
| 127.0.0.1      | root             | *836E283974EBE6EA32F95F890A91363F8427F78B |
| ::1            | root             | *836E283974EBE6EA32F95F890A91363F8427F78B |
| localhost      | debian-sys-maint | *1460ED35E5ABDBB887F9E5F57F40A2354610CDF3 |
| %              | test             | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |+----------------+------------------+-------------------------------------------+rows in set (0.00 sec)1234567891011

授权

grant all privileges on *.* to 'test'@'%'identified by '123456' with grant option;flush privileges;12

修改用户密码

update mysql.user set password=password('新密码') where User="test" and Host="localhost";1

删除用户

delete from user where User='test' and Host='localhost';


热门评论