问题
I have install mysql on digital ocean and trying to connect through php script and I got this error
mysqli_connect(): (HY000/2002): Connection refused in /var/www/waev.in/signup/ajax/send_code.php on line 9 Failed to connect to MySQL: Connection refused
What can be the issue :
my php script
<?php
include '../func/sms_function.php';
$mysql_host='{ip}';
$mysql_user='root';
$mysql_pass='********';
$my_db='wesearch_waev_user';
$con = mysqli_connect($mysql_host,$mysql_user,$mysql_pass);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
回答1:
Maybe this would be
$mysql_host="localhost";// for local server
Or
$mysql_host="$ip";// if database is in remote and IP is stored in $ip
回答2:
Check the port you are using on the server. MySQL needs to be running on the port 3306
来源:https://stackoverflow.com/questions/42327137/mysql-error-mysqli-connect-hy000-2002-connection-refused