PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > MySQL server running, PHP can't connect
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
MySQL server running, PHP can't connect

Réponse
 
LinkBack Outils de la discussion
Vieux 08/04/2008, 19h23   #1
scorpionbilli@googlemail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut MySQL server running, PHP can't connect

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 ';' or '\h' for . 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?
  Réponse avec citation
Vieux 08/04/2008, 20h37   #2
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: MySQL server running, PHP can't connect

scorpionbilli@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 ';' or '\h' for . 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.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 08/04/2008, 20h47   #3
scorpionbilli@googlemail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: MySQL server running, PHP can't connect

On Apr 8, 9:37 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> 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 ';' or '\h' for . 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?
  Réponse avec citation
Vieux 08/04/2008, 20h54   #4
scorpionbilli@googlemail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: MySQL server running, PHP can't connect

On Apr 8, 9:47 pm, scorpionbi...@googlemail.com wrote:
> On Apr 8, 9:37 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>
>
>
> > 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 ';' or '\h' for . 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.
  Réponse avec citation
Vieux 08/04/2008, 21h21   #5
scorpionbilli@googlemail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: MySQL server running, PHP can't connect

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.net> wrote:

>
> > > 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 ';' or '\h' for . 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?
  Réponse avec citation
Vieux 08/04/2008, 21h40   #6
Gordon Burditt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: MySQL server running, PHP can't connect

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


When you connect using a socket, the server and the client must
agree on the location of the socket.

>$ 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 ';' or '\h' for . Type '\c' to clear the buffer.


$ mysql -h localhost -u root
>mysql>


At this point, type \s [ENTER] at the prompt. It will tell you a
number of things. Look for the line that tells you about the path
name to the socket (usually ends in 'mysql.sock'), e.g.:

mysql>\s
....
UNIX Socket: /tmp/mysql.sock
....

>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)


perror 2 on my system is "no such file or directory".

>
>Any ideas what's going on?


PHP doesn't know the correct path for the socket.
In php.ini, there's a variable setting (likely commented out or
missing in the default distribution file):

mysql.default_socket = "/tmp/mysql.sock"

Now restart your web server.

/tmp/mysql.sock represents the correct socket pathname. Don't
assume it is literally correct just because that's what it is on
my system (FreeBSD). It is important that the server and the client
AGREE, much more important than what the actual path is. Your
server and the command-line client already seem to agree, so use
what they're using.


  Réponse avec citation
Vieux 08/06/2008, 22h01   #7
AnrDaemon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: MySQL server running, PHP can't connect

Greetings, scorpionbilli@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 ';' or '\h' for . 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 <anrdaemon@freemail.ru>

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h24.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,25027 seconds with 15 queries