解决Linux下mysql允许远程连接的问题

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)
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

创建用户

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)
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

授权

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

修改用户密码

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

删除用户

delete from user where User='test' and Host='localhost';
  
  
  • 1
					<link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-a47e74522c.css" rel="stylesheet">
            </div>

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

猜你喜欢

转载自blog.csdn.net/Z_Date/article/details/84786217
今日推荐