dbTalk Databases Forums  

mysqli socket error

comp.databases.mysql comp.databases.mysql


Discuss mysqli socket error in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
JRough
 
Posts: n/a

Default mysqli socket error - 03-08-2010 , 12:03 PM






How do you configure the mysqli socket in php.ini?
I'm getting this sql socket warning:warning: msqli::mysqli()
[mysqli.mysqli]: (HY000/2002): Can't connect to local MysQL server
through socket 'var/mysql/mysqlsock' (2)

I have the mysql socket and the mysqli socket set to the same
location /tmp/mysql.sock.
In my.cnf it is set to tmp/mysql.sock
[client]
port =3306
socket=/tmp/mysql.sock

in php.ini
mysql.default_socket = /tmp/mysql.sock
mysqli.default_port = 3306

; MySQL defaults.
mysqli.default_socket = /tmp/mysql.sock

are they supposed to be different locations?
thanks,

Reply With Quote
  #2  
Old   
J.O. Aho
 
Posts: n/a

Default Re: mysqli socket error - 03-08-2010 , 12:21 PM






JRough wrote:
Quote:
How do you configure the mysqli socket in php.ini?
I'm getting this sql socket warning:warning: msqli::mysqli()
[mysqli.mysqli]: (HY000/2002): Can't connect to local MysQL server
through socket 'var/mysql/mysqlsock' (2)

I have the mysql socket and the mysqli socket set to the same
location /tmp/mysql.sock.
Why not use the defaults? Makes it far simpler for you.


Quote:
In my.cnf it is set to tmp/mysql.sock
[client]
port =3306
socket=/tmp/mysql.sock

in php.ini
mysql.default_socket = /tmp/mysql.sock
mysqli.default_port = 3306

; MySQL defaults.
mysqli.default_socket = /tmp/mysql.sock
Assuming here, you are using the php through apache (or any other web server),
did you remember to restart the web service? If not, then the old settings are
used until you restart the service.


Quote:
are they supposed to be different locations?
No, as mysql has just one socket.


--

//Aho

Reply With Quote
  #3  
Old   
JRough
 
Posts: n/a

Default Re: mysqli socket error - 03-08-2010 , 12:36 PM



On Mar 8, 10:21*am, "J.O. Aho" <u... (AT) example (DOT) net> wrote:
Quote:
JRough wrote:
How do you configure the mysqli socket in php.ini?
I'm getting this sql socket warning:warning: *msqli::mysqli()
[mysqli.mysqli]: (HY000/2002): *Can't connect to local MysQL server
through socket 'var/mysql/mysqlsock' (2)

I have the mysql socket and the mysqli socket set to the same
location /tmp/mysql.sock.

Why not use the defaults? Makes it far simpler for you.

In my.cnf it is set to tmp/mysql.sock
[client]
port =3306
socket=/tmp/mysql.sock

in php.ini
mysql.default_socket = */tmp/mysql.sock
mysqli.default_port = 3306

; MySQL defaults.
mysqli.default_socket = */tmp/mysql.sock

Assuming here, you are using the php through apache (or any other web server),
did you remember to restart the web service? If not, then the old settings are
used until you restart the service.

are they supposed to be different locations?

No, as mysql has just one socket.

--

* //Aho
These are the defaults in the php.ini. They say default is /tmp/
mysql.sock.
Do you mean to remove the reference in my.cnf ? it also says /tmp/
mysql.sock.
I don't know where the var/mysql/mysqlsock(2) error is coming from.
Does it mean there are 2 mysql sockets?
I don't think I changed anything and I thought it was working but I
just started writing a script using mysqli.

Reply With Quote
  #4  
Old   
J.O. Aho
 
Posts: n/a

Default Re: mysqli socket error - 03-08-2010 , 12:58 PM



JRough wrote:

Quote:
These are the defaults in the php.ini. They say default is /tmp/
mysql.sock.
Default in a php.ini is empty values, at least in the Linux distros and Unixes
I have used.


Quote:
Do you mean to remove the reference in my.cnf ? it also says /tmp/
mysql.sock.
It's a quite unusual location for the socket file, and feels quite unsecure to
have it in /tmp. I would have set it in /var/run/mysqld/mysqld.sock (if you
have a such directory), it gives a slightly more restrictions than having it
in /tmp.


Quote:
I don't know where the var/mysql/mysqlsock(2) error is coming from.
Does it mean there are 2 mysql sockets?
No, it's the error number. It tells you that it tries to look for the socket
in var/mysql/mysqlsock, which would be relative to the directory from where
the php is executed (would say that the original path was missing the leading /).

You can always try to connect to the hostname of the machine (instead of
localhost/127.0.0.1), then it should connect to the port instead of using the
socket, which would be a work around for your configuration troubles.


Quote:
I don't think I changed anything and I thought it was working but I
just started writing a script using mysqli.
Using packages released by the OS maintainer are always better than using 3rd
party packages or compile those yourself, as those official packages will
always work.


--

//Aho

Reply With Quote
  #5  
Old   
JRough
 
Posts: n/a

Default Re: mysqli socket error - 03-08-2010 , 01:29 PM



On Mar 8, 10:58*am, "J.O. Aho" <u... (AT) example (DOT) net> wrote:
Quote:
JRough wrote:
These are the defaults in the php.ini. *They say default is /tmp/
mysql.sock.

Default in a php.ini is empty values, at least in the Linux distros and Unixes
I have used.

Do you mean to remove the reference in my.cnf ? *it also says /tmp/
mysql.sock.

It's a quite unusual location for the socket file, and feels quite unsecure to
have it in /tmp. I would have set it in /var/run/mysqld/mysqld.sock (if you
have a such directory), it gives a slightly more restrictions than havingit
in /tmp.

I don't know where the var/mysql/mysqlsock(2) error is coming from.
Does it mean there are 2 mysql sockets?

No, it's the error number. It tells you that it tries to look for the socket
in var/mysql/mysqlsock, which would be relative to the directory from where
the php is executed (would say that the original path was missing the leading /).

You can always try to connect to the hostname of the machine (instead of
localhost/127.0.0.1), then it should connect to the port instead of usingthe
socket, which would be a work around for your configuration troubles.

I don't think I changed anything and I thought it was working but I
just started writing a script using mysqli.

Using packages released by the OS maintainer are always better than using3rd
party packages or compile those yourself, as those official packages will
always work.

--

* //Aho
I commented out the defaul settings in php.ini to see if the socket
would change to another default and get rid of the error message but
it didn't.
So somewhere in my Mac, Apple is telling it to go to the var/mysql/
mysqlsock location I would like to find out where. But it was
working previously although I had it configured to a software IP
addres. I don't have a static IP address. It is software enabled.
So mysql requests were working find because it updates the IP address
and the name points to the latest IP. That was all working until I
got a new router from AT&T . It wouldn't reroute web traffoce to the
outside IP so to get this script done I turned it back to localhost
for testing. That should work but now it isn't. It is giving the
socket error. Maybe it was there before but I wasn't using localhost.

Reply With Quote
  #6  
Old   
JRough
 
Posts: n/a

Default Re: mysqli socket error - 03-08-2010 , 01:31 PM



On Mar 8, 10:58*am, "J.O. Aho" <u... (AT) example (DOT) net> wrote:
Quote:
JRough wrote:
These are the defaults in the php.ini. *They say default is /tmp/
mysql.sock.

Default in a php.ini is empty values, at least in the Linux distros and Unixes
I have used.

Do you mean to remove the reference in my.cnf ? *it also says /tmp/
mysql.sock.

It's a quite unusual location for the socket file, and feels quite unsecure to
have it in /tmp. I would have set it in /var/run/mysqld/mysqld.sock (if you
have a such directory), it gives a slightly more restrictions than havingit
in /tmp.

I don't know where the var/mysql/mysqlsock(2) error is coming from.
Does it mean there are 2 mysql sockets?

No, it's the error number. It tells you that it tries to look for the socket
in var/mysql/mysqlsock, which would be relative to the directory from where
the php is executed (would say that the original path was missing the leading /).

You can always try to connect to the hostname of the machine (instead of
localhost/127.0.0.1), then it should connect to the port instead of usingthe
socket, which would be a work around for your configuration troubles.

I don't think I changed anything and I thought it was working but I
just started writing a script using mysqli.

Using packages released by the OS maintainer are always better than using3rd
party packages or compile those yourself, as those official packages will
always work.

--

* //Aho
Do I have to open up 3306 on the router?

Reply With Quote
  #7  
Old   
JRough
 
Posts: n/a

Default Re: mysqli socket error - 03-08-2010 , 01:52 PM



On Mar 8, 10:58*am, "J.O. Aho" <u... (AT) example (DOT) net> wrote:
Quote:
JRough wrote:
These are the defaults in the php.ini. *They say default is /tmp/
mysql.sock.

Default in a php.ini is empty values, at least in the Linux distros and Unixes
I have used.

Do you mean to remove the reference in my.cnf ? *it also says /tmp/
mysql.sock.

It's a quite unusual location for the socket file, and feels quite unsecure to
have it in /tmp. I would have set it in /var/run/mysqld/mysqld.sock (if you
have a such directory), it gives a slightly more restrictions than havingit
in /tmp.

I don't know where the var/mysql/mysqlsock(2) error is coming from.
Does it mean there are 2 mysql sockets?

No, it's the error number. It tells you that it tries to look for the socket
in var/mysql/mysqlsock, which would be relative to the directory from where
the php is executed (would say that the original path was missing the leading /).

You can always try to connect to the hostname of the machine (instead of
localhost/127.0.0.1), then it should connect to the port instead of usingthe
socket, which would be a work around for your configuration troubles.

I don't think I changed anything and I thought it was working but I
just started writing a script using mysqli.

Using packages released by the OS maintainer are always better than using3rd
party packages or compile those yourself, as those official packages will
always work.

--

* //Aho
I did try changing all the mysql socket defaults to where it thinks it
is /var/mysql/mysql.socket.
I changed the mysqli default socket, the mysql default socket and the
my.conf to /var/mysql/mysql.socket
I checked the permission of this directory. that is the only other
thing I think it can be.
drwxr-xr-x 2 _mysql wheel 68 Dec 28 11:56 .
drwxr-xr-x 26 root wheel 884 Dec 28 11:56 ..
thanks,

Reply With Quote
  #8  
Old   
J.O. Aho
 
Posts: n/a

Default Re: mysqli socket error - 03-08-2010 , 02:23 PM



JRough wrote:


Quote:
I commented out the defaul settings in php.ini to see if the socket
would change to another default and get rid of the error message but
it didn't.
So somewhere in my Mac, Apple is telling it to go to the var/mysql/
mysqlsock location I would like to find out where.
PHP has a default built in path in Unix and Linux, it kind of looks like
broken IMHO. Keep in mind that you need to restart the apache (stop/start)
before changes in the php.ini will take affect.


Quote:
But it was
working previously although I had it configured to a software IP
addres. I don't have a static IP address. It is software enabled.
So mysql requests were working find because it updates the IP address
and the name points to the latest IP. That was all working until I
got a new router from AT&T . It wouldn't reroute web traffoce to the
outside IP so to get this script done I turned it back to localhost
for testing. That should work but now it isn't. It is giving the
socket error. Maybe it was there before but I wasn't using localhost.
localhost calls are directed to use the socket, which is the big difference
between the two cases, as it previously used tcp.


Quote:
Do I have to open up 3306 on the router?
Only if traffic would go somehow out from the router and then back in, it
shouldn't ever get our of the router.


Quote:
I did try changing all the mysql socket defaults to where it thinks it
is /var/mysql/mysql.socket.
I changed the mysqli default socket, the mysql default socket and the
my.conf to /var/mysql/mysql.socket
I checked the permission of this directory. that is the only other
thing I think it can be.
drwxr-xr-x 2 _mysql wheel 68 Dec 28 11:56 .
drwxr-xr-x 26 root wheel 884 Dec 28 11:56 ..
The permission looks okey, how about the socket file itself?

srwxrwxrwx 1 mysql mysql 0 2009-10-01 06:58 /var/run/mysqld/mysqld.sock


If php still says "var/mysql/mysqlsock" after restart of apache, then check if
you run suExec on apache, as that will allow you to have a custom php.ini for
each "user", in that case the php.ini would be in the users "home directory".


--

//Aho

Reply With Quote
  #9  
Old   
JRough
 
Posts: n/a

Default Re: mysqli socket error - 03-08-2010 , 02:45 PM



On Mar 8, 12:23*pm, "J.O. Aho" <u... (AT) example (DOT) net> wrote:
Quote:
JRough wrote:
I commented out the defaul settings in php.ini to see if the socket
would change to another default and get rid of the error message but
it didn't.
So somewhere in my Mac, Apple is telling it to go to the var/mysql/
mysqlsock location *I would like to find out where.

PHP has a default built in path in Unix and Linux, it kind of looks like
broken IMHO. Keep in mind that you need to restart the apache (stop/start)
before changes in the php.ini will take affect.

But it was
working previously although I had it configured to a software IP
addres. *I don't have a static IP address. *It is software enabled.
So mysql requests were working find because it updates the IP address
and the name points to the latest IP. *That was all working until I
got a new router from AT&T . * It wouldn't reroute web traffoce to the
outside IP so to get this script done I turned it back to localhost
for testing. *That should work but now it isn't. *It is giving the
socket error. *Maybe it was there before but I wasn't using localhost..

localhost calls are directed to use the socket, which is the big difference
between the two cases, as it previously used tcp.

Do I have to open up 3306 on the router?

Only if traffic would go somehow out from the router and then back in, it
shouldn't ever get our of the router.

I did try changing all the mysql socket defaults to where it thinks it
is /var/mysql/mysql.socket.
I changed the mysqli default socket, the mysql default socket and the
my.conf to /var/mysql/mysql.socket
I checked the permission of this directory. *that is the only other
thing I think it can be.
drwxr-xr-x * 2 _mysql *wheel * 68 Dec 28 11:56 .
drwxr-xr-x *26 root * *wheel *884 Dec 28 11:56 ..

The permission looks okey, how about the socket file itself?

srwxrwxrwx 1 mysql mysql 0 2009-10-01 06:58 /var/run/mysqld/mysqld.sock

If php still says "var/mysql/mysqlsock" after restart of apache, then check if
you run suExec on apache, as that will allow you to have a custom php.inifor
each "user", in that case the php.ini would be in the users "home directory".

--

* //Aho
Okay, I think the problem is closer to being solved.
I changed the my.cnf and forced it to find the mysql socket where it
is asking to /var/mysql/mysql.socket.
In fact, I went to the /var/mysql/mysql.sock directory and there is a
mysql.socket file there. So I guess it was conflicting with the one
in the php.ini /tmp/mysql.socket.
I changed the php.ini defaults in both places, mysql and mysqli, and I
changed the my.conf all to /var/mysql/mysql.socket.
then I tried to restart mysql in the control panel and I could stop it
but not restart it. So I don't know if it is running or not. I can't
seem to do a ps aux | mysql without an error.
I tried to find the running process.
Somehow I can't shutdown the old mysqld process and start the new one
with the socket hopefully in the right place.


Here is the sequence:
100308 12:28:55 mysqld_safe A mysqld process already exists
sh-3.2# mysqladmin -u root -p shutdown
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/
mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock'
exists!
sh-3.2# ps mysql
ps: illegal option -- y
usage: ps [-AaCcEefhjlMmrSTvwXx] [-O fmt | -o fmt] [-G gid[,gid...]]
[-u]
[-p pid[,pid...]] [-t tty[,tty...]] [-U user[,user...]]
ps [-L]
sh-3.2# mysqladmin -u root -p status
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/
mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock'
exists!

Reply With Quote
  #10  
Old   
J.O. Aho
 
Posts: n/a

Default Re: mysqli socket error - 03-09-2010 , 12:07 AM



JRough wrote:

Quote:
Okay, I think the problem is closer to being solved.
I changed the my.cnf and forced it to find the mysql socket where it
is asking to /var/mysql/mysql.socket.
In fact, I went to the /var/mysql/mysql.sock directory and there is a
mysql.socket file there. So I guess it was conflicting with the one
in the php.ini /tmp/mysql.socket.
I changed the php.ini defaults in both places, mysql and mysqli, and I
changed the my.conf all to /var/mysql/mysql.socket.
then I tried to restart mysql in the control panel and I could stop it
but not restart it. So I don't know if it is running or not. I can't
seem to do a ps aux | mysql without an error.
I tried to find the running process.
Of course that will cause an error, as you pipe the output from "ps aux" to
"mysql", the command should have been:

ps aux | grep mysql


Quote:
Somehow I can't shutdown the old mysqld process and start the new one
with the socket hopefully in the right place.
you can kill it manually: kill -9 <pid>

The pid is the first number on the row with mysqld when you do "ps aux | grep
mysql".



--

//Aho

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.