B.5.3.6 How to Protect or Change the MySQL Unix Socket File
The default location for the Unix socket file that the server uses for communication with local clients is/tmp/mysql.sock
. (For some distribution formats, the directory might be different, such as /var/lib/mysql
for RPMs.)
On some versions of Unix, anyone can delete files in the /tmp
directory or other similar directories used for temporary files. If the socket file is located in such a directory on your system, this might cause problems.
On most versions of Unix, you can protect your /tmp
directory so that files can be deleted only by their owners or the superuser (root
). To do this, set the sticky
bit on the /tmp
directory by logging in as root
and using the following command:
shell> chmod +t /tmp
You can check whether the sticky
bit is set by executing ls -ld /tmp
. If the last permission character is t
, the bit is set.
Another approach is to change the place where the server creates the Unix socket file. If you do this, you should also let client programs know the new location of the file. You can specify the file location in several ways:
Specify the path in a global or local option file. For example, put the following lines in
/etc/my.cnf
:[mysqld] socket=/path/to/socket [client] socket=/path/to/socket
Specify a
--socket
option on the command line to mysqld_safe and when you run client programs.Set the
MYSQL_UNIX_PORT
environment variable to the path of the Unix socket file.Recompile MySQL from source to use a different default Unix socket file location. Define the path to the file with the
MYSQL_UNIX_ADDR
option when you run CMake. See Section 2.8.4, “MySQL Source-Configuration Options”.
You can test whether the new socket location works by attempting to connect to the server with this command:
shell> mysqladmin --socket=/path/to/socket version