我在这里查看了大约 50 个相同的问题,但似乎没有一个能解决我的问题。我无法通过 php 脚本远程连接到我的 MySQL 数据库,但是!! 连接 mysql -u admin -p -h 172.16.2.93
有效。
这是我使用的代码
<?php
session_start();
// initializing variables
$username = "";
$email = "";
$errors = array();
$dbhost = "172.16.2.93";
$dbuser = "admin";
$dbpass = "mariadb";
$dbname = "registration";
// connect to the database
$db = mysqli_connect("$dbhost", "$dbuser", "$dbpass", "$dbname") or die(mysql_error());
错误
当我访问脚本连接到的网站时,/var/log/httpd/access_log
中出现以下错误:
[:error] [pid 14797] [client 172.16.2.143:55201] PHP 警告:mysqli_connect(): (HY000/2003): 无法连接到“172.16.2.93”上的 MySQL 服务器 (13 ) 在/var/www/html/server.php 第 15 行
我尝试过的事情
将
<bind-address
更改为bind-address=0.0.0.0
和#bind-address
关闭所有防火墙
运行命令
setsebool httpd_can_network_connect=1
在
中禁用 selunix/etc/selinux/config
编辑:问题似乎已经解决。使用 mysql_native_password
创建用户 remote@%
后,我能够通过脚本访问数据库。
最佳答案
请检查 Mysql 是否在端口 3306 上从客户端响应,如果它是不同的端口,则必须在 mysqli_connect 中提及该端口($host、$user、$password、$dbname、$port、$socket)。
您一定是缺少端口参数
关于php - 无法使用 PHP 脚本远程连接到 MySQL 错误 (13),通过 CLI 连接有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54804114/