当前位置:Gxlcms > 数据库问题 > 开启mysql远程访问过程中所遇常见问题的解决办法

开启mysql远程访问过程中所遇常见问题的解决办法

时间:2021-07-01 10:21:17 帮助过:19人阅读

谷歌了一下之后,原来是在mysql的my.cnf中有下面一段代码:

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address           = 127.0.0.1  #这里默认监听本地localhost

如果要让mysql监听到其他的地址,可以将bind-address = 127.0.0.1注释掉。 
或者将bind-address = 0.0.0.0监听所有的地址

屏蔽掉之后再次运行代码又出现:Host ‘192.168.10.83‘ is not allowed to connect to this MySQL server 
技术图片 
解决方法: 
如果想让192.168.10.83能够连接到本地的这个数据库,要让数据库给其分配权限,登录mysql,执行:(username 和 password是登录mysql的用户名和密码)

GRANT ALL PRIVILEGES ON *.* TO username‘@192.168.10.83‘ IDENTIFIED BY passwordWITH GRANT OPTION;

如果要想所有的外部ip地址都能够访问使用mysql,可以执行下面:

GRANT ALL PRIVILEGES ON *.* TO username‘@%‘ IDENTIFIED BY passwordWITH GRANT OPTION;

之后执行刷新数据库:

flush privileges;

如果要查看用户的权限,可以执行:

> show grants for root@192.168.10.83

技术图片

以上摘抄于:

http://www.cnblogs.com/zihanxing/p/7049244.html

 

CentOS7和CentOS6怎样开启MySQL远程访问

CentOS6开启MySQL远程访问

1.开放MySQL访问端口3306

修改防火墙配置文件

vi /etc/sysconfig/iptables 

加入端口配置     

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

重新加载规则

service iptables restart  


2.修改mysql库里的host

登录mysql;

use mysql

update user set host=‘%‘ where user=‘root‘ and host=‘localhost‘;

记得一定还得修改密码,因为这时密码已失效,虽然本地还可以原密码登录,可远程改了host后还是没法访问

UPDATE user SET password=password("root") WHERE user=‘root‘; 

flush privileges;

3.重启mysql,远程就可以访问了

service mysqld restart;


 CentOS7开启MySQL远程访问

CentOS7这个版本的防火墙默认使用的是firewall,与之前的版本使用iptables不一样。按如下方便配置防火墙:

1、关闭防火墙:sudo systemctl stop firewalld.service


2、关闭开机启动:sudo systemctl disable firewalld.service

 

3、安装iptables防火墙

执行以下命令安装iptables防火墙:sudo yum install iptables-services

 

4、配置iptables防火墙,打开指定端口(CentOS6一样)

5、设置iptables防火墙开机启动:sudo systemctl enable iptables

6、之后的和CentOS6一样


CentOS下防火墙的基本操作命令

CentOS 配置防火墙操作实例(启、停、开、闭端口):

 

注:防火墙的基本操作命令:

查询防火墙状态:

[root@localhost ~]# service   iptables status

停止防火墙:

[root@localhost ~]# service   iptables stop 

启动防火墙:

[root@localhost ~]# service   iptables start 

重启防火墙:

[root@localhost ~]# service   iptables restart

永久关闭防火墙:

[root@localhost ~]# chkconfig   iptables off

永久关闭后启用:

[root@localhost ~]# chkconfig   iptables on

以上摘抄于:

https://www.cnblogs.com/qianzf/p/6995140.html

 

如果上述列出的方案不能够解决你遇到的问题,可以参考如下mysql官方网页:

https://dev.mysql.com/doc/refman/5.6/en/problems-connecting.html

开启mysql远程访问过程中所遇常见问题的解决办法

标签:端口   报错   遇到的问题   nts   cli   监听   火墙   sys   打开   

人气教程排行