PHP MySQLi权限被拒绝,但可以从MySQL CLI使用

编程入门 行业动态 更新时间:2024-10-17 07:32:49
本文介绍了PHP MySQLi权限被拒绝,但可以从MySQL CLI使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我收到错误

Failed to connect to MySQL: Permission denied

从PHP与MySQL,MySQLi和PDO连接到远程MySQL主机时.

When connecting from PHP with MySQL, MySQLi and PDO to a remote MySQL host.

但是,如果我在命令行上从同一主机通过MySQL以相同的凭据连接到同一主机,则效果很好.

However, if I connect to the same host, with the same credentials through MySQL from the same host on the command line it works perfectly.

所以我要假设它是一个PHP配置问题?

So I'm making the assumption its a PHP config problem?

连接自

PHP 5.6.40 (Client API version => mysqlnd 5.0.11-dev) MySQL 5.5.59

连接到

PHP 5.6.23 (Client API version => mysqlnd 5.0.11-dev) MySQL 5.5.52

有人知道为什么我可以从命令行连接到MySQL,但不能从PHP连接到具有完全相同凭据的同一主机吗?

Anyone got any ideas why I can connect from the command line to MySQL but not from PHP to the same host with the exact same credentials?

推荐答案

我猜您在服务器上启用了SELinux. 默认情况下,它不允许apache进程初始化传出网络连接.

I guess that you have SELinux enabled on your server. By default it doesn't allow apache process to initialize outgoing network connections.

serverfault/a/456875/442205

要检查SELinux

To check SELinux

sestatus

查看在httpd进程上设置了哪些标志

To see what flags are set on httpd processes

getsebool -a | grep httpd

允许Apache通过SELinux连接到远程数据库

To allow Apache to connect to remote database through SELinux

setsebool httpd_can_network_connect_db 1

使用-P选项使更改永久生效.如果没有此选项,则布尔值将在重新启动时重置为0.

Use -P option makes the change permanent. Without this option, the boolean would be reset to 0 at reboot.

setsebool -P httpd_can_network_connect_db 1

更多推荐

PHP MySQLi权限被拒绝,但可以从MySQL CLI使用

本文发布于:2023-11-28 15:16:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642923.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:被拒   权限   MySQLi   PHP   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!