PHP和MYSQL连接的拒绝权限问题 [英] Problem of Denied Permissions in connection between PHP and MYSQL

查看:41
本文介绍了PHP和MYSQL连接的拒绝权限问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PHP 连接 CRUD Simple,连接 MySQL 中的数据库.问题是在 mysql_connect 函数中,在宿主变量中,如果我传递 String localhost,它会连接并向我显示数据库的信息.问题是当我把 MySQL 数据库所在的主机的 IP,它显示我权限被拒绝.我已经使用以下命令将权限发送给用户 carlos:

I am trying to connect a CRUD Simple with PHP, connecting a database in MySQL. The problem is that in the mysql_connect function, in the host variable, if I pass the String localhost, it connects and shows me the information of the database. The problem is when I put the IP of the host where the MySQL database is located, it shows me Permission denied. I already send the privileges to the user carlos with the following command:

GRANT ALL PRIVILEGES ON * . * TO 'carlos'@'%';

这是连接代码,其余代码不影响,因为这组是程序的第一行:

This is the connection code, the rest of the code does not affect, since this set are the first lines of the program:

$link = mysqli_connect("192.168.0.18:3306", "carlos", "abc123", "distribuidos") or die ('Error. ' . mysqli_connect_error());

使用本地主机,连接工作:

With localhost, the connection work:

$link = mysqli_connect("localhost", "carlos", "abc123", "distribuidos") or die ('Error. ' . mysqli_connect_error());

应该注意的是,我还使用已经打开的端口配置了防火墙,在本例中为 3306,如果我使用命令 mysql -u carlos -h 192.168 连接.来自另一台机器的 0.18 -p 连接我没有问题.

It should be noted that I have also configured the firewall with the ports already open, in this case 3306, and if I connect with the command mysql -u carlos -h 192.168.0.18 -p from another machine connects me without problem.

我使用的是 php 7.3 和 CentOS 7.

I am using php 7.3 and CentOS 7.

解决方案

我的解决方案是在 Linux 上执行下一个命令:sudo setsebool -P httpd_can_network_connect 1

My solution is execute the next command on Linux: sudo setsebool -P httpd_can_network_connect 1

推荐答案

可以检查的三件事

  1. 请检查您的端口是否打开

  1. 删除/etc/mysql/my.cnf 中的绑定地址 127.0.0.1

  1. apache 没有配置为外部访问.试试 sudo setsebool -P httpd_can_network_connect 1

这篇关于PHP和MYSQL连接的拒绝权限问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆