mysql.sock Problems

JavaScript Editor Js editor     Website development 



Main Page

Previous Page
Next Page

mysql.sock Problems

Client programs use the mysql.sock socket to access the mysqld server on Unix and Mac OS X systems (MySQL on Windows uses TCP/IP). Should the client applicationfor example, mysql or a PHP scriptbe unable to find the socket, you'll encounter problems accessing MySQL. There are two reasons why this might occur:

  • The mysql.sock file has been deleted.

  • The mysql.sock file is located other than where the client program is looking for it.

Normally, mysql.sock is stored in the /tmp directory. On some installations, the socket will be in /var/lib/mysql instead. Mac OS X Server puts the MySQL socket in /var/mysql.

You can prevent the first problem by protecting the mysql.sock so that it cannot be deleted.

To protect mysql.sock:

1.
Access your server using a terminal application.

2.
Add a "sticky bit" to the /tmp directory.

sudo chmod +t /tmp

Adding a sticky bit to a directory means that all of the files therein can be deleted only by the owner of the file or by a superuser. One of the reasons MySQL may not be able to find the socket is that it has been inadvertently deleted by another user or application. This step will prevent that from occurring again.

3.
Enter the computer's administrative password at the prompt (Figure A.8).

Figure A.8. On Unix and Mac OS X, the chmod command can be applied to the /tmp directory to protect the mysql.sock socket.


4.
Restart MySQL.

For the second problem, there are two fixes. First, you can tell the client programs where to find mysql.sock. This is editable within the php.ini file, and you can indicate the socket when connecting via the mysql client (Figure A.9). The second option is to create a symbolic link so that where the client thinks the socket should be (e.g., /tmp/mysql.sock) points to where the socket actually is (e.g., /var/mysql/mysql.sock). I'll show you how to do that now.

Figure A.9. I can tell the mysql client where the socket is so that it can communicate with the MySQL server.


To create a symbolic link:

1.
Access your server using a terminal application.

2.
Locate the mysql.sock socket (Figure A.10).

Figure A.10. MySQL needs to be able to find the mysql.sock socket in order for clients to connect to the server. So I first find out for myself where it is.


sudo find / -name 'mysql.sock'

This command will search through the entire server to find mysql.sock. This assumes, of course, that the MySQL server is currently running.

Enter the computer's administrative password at the prompt.

3.
Create a symbolic link from where MySQL thinks the socket should be to where the socket actually is (Figure A.11).

Figure A.11. By creating a symbolic link, I assure that my client applications will be able to find the socket.


sudo ln -s /path/to/actual/mysql.sock/tmp/mysql.sock

A symbolic link will trick MySQL into thinking that /tmp/mysql.sock is the real socket, even when it is not.

Tips

  • As a reminder, the mysql.sock file only exists on Unix computers (and Mac OS X) and while the MySQL server is running. It's possible that a client could not find the socket because the server is not running.

  • You can also specify the socket's location by using either an option file or the --socket parameter when mysqld is started.



Previous Page
Next Page


JavaScript Editor Js editor     Website development


©

Waist training . Air conditioner replacement Sacramento