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,
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.
> 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 having it
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 using the
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 using 3rd
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.
> 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.ini for
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!
> 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
> 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
A hostname of 'localhost' uses the local socket. That exact string
(case sensitive) is magic.
A hostname of '127.0.0.1' uses TCP/IP.
A hostname of 'Localhost' uses TCP/IP.
A hostname of 'localHost' uses TCP/IP.
A hostname of 'localhosT' uses TCP/IP.
A hostname of the local IP address of the machine uses TCP/IP.
A hostname that resolves in DNS to the local IP address of the
machine uses TCP/IP.
Using the local socket instead of TCP/IP is rumored to be faster.
If you want to test this, fire up the command-line utility with
the hostname you want to test (you have to straighten out the socket
location if you want to use '-h localhost'):
mysql -h 127.0.0.1
(with possibly additional username and password parameters) and
enter \s at the command-line prompt. It will spit out a screenful
of information. Look at the Connection: line, and note whether it
says "via local socket" vs. "via TCP/IP".
>> 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.
If you're going to use a local socket, it's the responsibility of
the admin / programmer / user (whichever is specifying the socket
location) to ensure that the server, the command-line client
utilities, and PHP all agree on the location of the socket. An
exception occurs if you are running two instances of the server on
the same host, in which case it is even more important to ensure
that the client command-line utilities and PHP use the same socket
location as the *correct* server instance.
Possibly more importantly, the local socket cannot usually be connected
to from anywhere OTHER than the local machine, even via a tunnel
mechanism. So it's kind of hard to accidently leak data via a guessable
or retained password.
--
81. If I am fighting with the hero atop a moving platform, have
disarmed him, and am about to finish him off and he glances behind
me and drops flat, I too will drop flat instead of quizzically
turning around to find out what he saw. --Evil Overlord list