By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,743 Members | 1,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,743 IT Pros & Developers. It's quick & easy.

MySQL server running, PHP can't connect

P: n/a
Hi,

The local mysql server is running on my Macbook. I can access it
through the console client:

$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.45 MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>

But when I launch a PHP script that tries to connect to it, I get an
error:

$link = mysql_connect("localhost", "root", "");

Warning: mysql_connect(): Can't connect to local MySQL server through
socket '/var/mysql/mysql.sock' (2)

Any ideas what's going on?
Apr 8 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
sc***********@googlemail.com wrote:
Hi,

The local mysql server is running on my Macbook. I can access it
through the console client:

$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.45 MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>

But when I launch a PHP script that tries to connect to it, I get an
error:

$link = mysql_connect("localhost", "root", "");

Warning: mysql_connect(): Can't connect to local MySQL server through
socket '/var/mysql/mysql.sock' (2)

Any ideas what's going on?
Does /var/mysql/mysql.sock exist? What are its permissions?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Apr 8 '08 #2

P: n/a
On Apr 8, 9:37 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
scorpionbi...@googlemail.com wrote:
Hi,
The local mysql server is running on my Macbook. I can access it
through the console client:
$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.45 MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
But when I launch a PHP script that tries to connect to it, I get an
error:
$link = mysql_connect("localhost", "root", "");
Warning: mysql_connect(): Can't connect to local MySQL server through
socket '/var/mysql/mysql.sock' (2)
Any ideas what's going on?

Does /var/mysql/mysql.sock exist? What are its permissions?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
No, /var/mysql does't exist. locate mysql.sock shows one at /private/
tmp/mysql.sock .

Should I configure PHP to use that, or configure MySQL to place the
socket somewhere else?
Apr 8 '08 #3

P: n/a
On Apr 8, 9:47 pm, scorpionbi...@googlemail.com wrote:
On Apr 8, 9:37 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
scorpionbi...@googlemail.com wrote:
Hi,
The local mysql server is running on my Macbook. I can access it
through the console client:
$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.45 MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
But when I launch a PHP script that tries to connect to it, I get an
error:
$link = mysql_connect("localhost", "root", "");
Warning: mysql_connect(): Can't connect to local MySQL server through
socket '/var/mysql/mysql.sock' (2)
Any ideas what's going on?
Does /var/mysql/mysql.sock exist? What are its permissions?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

No, /var/mysql does't exist. locate mysql.sock shows one at /private/
tmp/mysql.sock .

Should I configure PHP to use that, or configure MySQL to place the
socket somewhere else?
I forgot to add: /var, /tmp and /etc are all linked to /private
subdirectories, so the mysql.sock would be reachable at /tmp/
mysql.sock .

Mh. I'll try symlinking /var/mysql/mysql.sock to that.
Apr 8 '08 #4

P: n/a
On Apr 8, 9:54 pm, scorpionbi...@googlemail.com wrote:
On Apr 8, 9:47 pm, scorpionbi...@googlemail.com wrote:
On Apr 8, 9:37 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
scorpionbi...@googlemail.com wrote:
Hi,
The local mysql server is running on my Macbook. I can access it
through the console client:
$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.45 MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
But when I launch a PHP script that tries to connect to it, I get an
error:
$link = mysql_connect("localhost", "root", "");
Warning: mysql_connect(): Can't connect to local MySQL server through
socket '/var/mysql/mysql.sock' (2)
Any ideas what's going on?
Does /var/mysql/mysql.sock exist? What are its permissions?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
No, /var/mysql does't exist. locate mysql.sock shows one at /private/
tmp/mysql.sock .
Should I configure PHP to use that, or configure MySQL to place the
socket somewhere else?

I forgot to add: /var, /tmp and /etc are all linked to /private
subdirectories, so the mysql.sock would be reachable at /tmp/
mysql.sock .

Mh. I'll try symlinking /var/mysql/mysql.sock to that.
Don't have access to root right now. Is there any other way of doing
this?
Apr 8 '08 #5

P: n/a
Greetings, sc***********@googlemail.com.
In reply to Your message dated Tuesday, April 8, 2008, 22:23:20,
The local mysql server is running on my Macbook. I can access it
through the console client:
$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.45 MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>>
But when I launch a PHP script that tries to connect to it, I get an
error:
$link = mysql_connect("localhost", "root", "");
First: Don't use 'root' in any other case than maintenance purposes.
Warning: mysql_connect(): Can't connect to local MySQL server through
socket '/var/mysql/mysql.sock' (2)
Any ideas what's going on?
RTFM, seriously.
http://www.php.net/manual/en/function.mysql-connect.php

Note: Whenever you specify "localhost" or "localhost:port" as server, the
MySQL client library will override this and try to connect to a local socket
(named pipe on Windows). If you want to use TCP/IP, use "127.0.0.1" instead of
"localhost". If the MySQL client library tries to connect to the wrong local
socket, you should set the correct path as Runtime Configuration in your PHP
configuration and leave the server field blank.
From my experience, this may cause some unexpected things, at least in
Windows.

Try
$link = mysql_connect("127.0.0.1", "username", "password");
--
Sincerely Yours, AnrDaemon <an*******@freemail.ru>

Jun 27 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.