用户权限问题:https://blog.csdn.net/weixin_43670802/article/details/103019598
Linux下修改Mysql默认的3306端口
如下:
1、登录Mysql后,查看当前端口
mysql> show global variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0.00 sec)
2. 修改端口,
编辑 /etc/my.cnf文件。
新增 port=3301 参数,如下:
[root@test etc]# vi /etc/my.cnf
[mysqld]
port=3301
...
....
如果文件中有bind-address = 127.0.0.1
则需要注掉,不然mysql只能被远端机自身访问。
3. 重新启动mysql
[root@test ~]# service mysql restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
4.再次登录后检查端口已修改为’3301’.
mysql> show global variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3301 |
+---------------+-------+
1 row in set (0.00 sec)
如果如此还无法远程管理的话,则有可能是一下两点原因:
- Linux防火墙未开MySQL端口
- 服务商设有安全组,需要自行开放端口
1.开放本端口:
1、打开防火墙配置文件
vi /etc/sysconfig/iptables
2、增加下面一行
-A INPUT -m state --state NEW -m tcp -p tcp --dport 54188 -j ACCEPT
3、重启防火墙
service iptables restart
注意:增加的开放3306端口的语句一定要在icmp-host-prohibited之前
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -i eth0 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
-A FORWARD -p icmp -j ACCEPT
-A FORWARD -i lo -j ACCEPT
-A FORWARD -i eth0 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
2.开启安全组(如已开启请忽略)
感谢大佬:https://blog.csdn.net/vtopqx/article/details/85640809
感谢大佬:https://www.cnblogs.com/uoar/p/8056174.html