Unable to connect to local MySQL database

I have this error:

Warning: mysql_connect(): [2002] Connection refused (trying to connect via tcp://127.0.0.1:3306) 

I saw a similar question, and I tried the solution by changing localhost to 127.0.0.1 , but it still does not work. I am using Mac OS X Lion. Please any help would be appreciated

This is the PHP code that I use to connect:

 <?php require("constants.php"); //open database $connect = mysql_connect(DB_SERVER,DB_USER,DB_PASS) or die('error connecting: ' . mysql_error()); mysql_select_db(DB_NAME)or die('error selecting db: ' . mysql_error());//select database ?> 
+5
source share
2 answers

Try to make sure your firewall is open for connections on port 3306.

The command should be ipfw set enable 3306 , but if you want, you can learn more about setting firewall permissions .

Another thing may be to make sure MySQL is listening on port 3306, edit my.ini and install

 [client] port=3306 

And then restart MySQL.

0
source

I had this problem before. You can fix this by commenting on "skip-networking" in the configuration. (my.ini or my.cnf, it's /etc/mysql/my.cnf on Linux, not sure about Mac)

- change
Alternatively, you can try typing "netstat" in the Terminal to make sure the mysql list is there (it should be something like 127.0.0.1:mysql or 127.0.0.1{306). If it is not specified, MySQL is either not running or could not bind.

0
source

All Articles