Mysql error : mysqli_connect(): (HY000/2002): Connection refused

若如初见. 提交于 2019-12-12 23:03:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!