mysql_connect(): No connection could be made because the target machine actively refused it

后端 未结 10 1874
长情又很酷
长情又很酷 2020-11-30 12:41

I have this problem when I am trying to run my PHP MySQL script. When I try to run my .php file this is what I get.

mysql_connect(): No connection could be m         


        
相关标签:
10条回答
  • 2020-11-30 12:54

    I had the same problem.

    There are two database engines - MySQL DB and Maria DB. In your system, the database engine which is working may not over the default port. So check the active database engine and its port. Connect the database using:

    mysqli_connect(host, username, password, dbname, port, socket)

    for example:

    mysqli_connect("localhost", "username", "password", "dbname", "3307")

    The port number is available in the my.ini file or in the status menu of wampserver.

    0 讨论(0)
  • 2020-11-30 12:56

    I had the same problem. The issue was that MySql was not running on Xampp so I had to run it for everything to work.

    So kindly ensure MySql is running on your localhost. Go to Xampp [or other localhost] control panel and click start/run under Mysql ].

    0 讨论(0)
  • 2020-11-30 12:58

    Make sure your mysql Service is running, by going to check in Services: in Search type: Services -> check mysql, start service if it's not running.

    0 讨论(0)
  • 2020-11-30 12:59

    This error is NOT password related.

    Password related errors display a response from MySQL server. The subject response is NOT coming from MySQL server, but from the client itself. It could not connect to the server because the MACHINE (not the server) refused it, so, it was more likely to be a network issue or some other thing.

    Try connecting to 127.0.0.1. Also check the port you are connecting to and which port is mysql running. Check for firewalls blocking connections. Are you sure is MySQL Server running?

    This answer may have additional info: PHP -MySQL:No connection could be made

    0 讨论(0)
  • 2020-11-30 13:01

    It looks like you forgot to add your password to your connection. Also, you should not use mysql connect anymore as it is officially depreciated. Use MYSQLi or PDO instead. An example of this would be:

    $connection= mysqli_connect("localhost", "root", "password", "database")
    or die(mysqli_error("error connecting to database"));
    
    0 讨论(0)
  • 2020-11-30 13:05

    Okay I fixed this error! there is no coding mistakes your SQL connection. it's caused by port# for SQL. go to your XAmp or wamp tools from active drop down and select "use a port other than 'given #' ". Then enter 3306 there. It will fix the issue. Thanks.

    0 讨论(0)
提交回复
热议问题