Rasheeq Ishmam
Rasheeq Ishmam

Reputation: 327

Connection refused for connecting with MySQL server using php in XAMPP(MacOS)

I am new to database. I was trying to connect mysql server with php code. But I don't know why I am getting error for connection.(I tried in windows changing the "localhost:8080" to "localhost" and it worked perfectly.)

MyCode:

<?php

$link = mysqli_connect("localhost:8080","root","","test1");

if($link === false){
    die("Error: Could not connect. ".mysqli_connect_error());
}

Refused Warning: enter image description here

XAMPP Port: enter image description here

Upvotes: 0

Views: 4786

Answers (3)

Drishti Jain
Drishti Jain

Reputation: 89

Change localhost to 127.0.0.1

I spent a day trying to solve it. mysqli was giving error with localhost.

Upvotes: 0

ooOlly
ooOlly

Reputation: 2127

Struggled for half day…… I used XAMPP 8 and connection to MySQL keep refuesed(errno 61). Actually XAMPP install MySQL in VM, so connect it via IP address show in XAMPP. There is no MySQL server on localhost. enter image description here

Change localhost to XAMPP IP address work for me.

db = pymysql.connect(host="192.168.64.2", port=3306, user="test", password='test', db="test")

Upvotes: 0

mail2bapi
mail2bapi

Reputation: 1617

localhost:8080 is for you web server. If your MySQL server runs on default settings, use port 3306. localhost:3306.

$link = mysqli_connect("localhost:3306","root","","test1");

Hope this helps you.

Upvotes: 1

Related Questions