MySQL protects or changes socket file/tmp/mysql.sock

Source: Internet
Author: User
Tags command line socket versions

The default location for a UNIX socket file that the server uses to communicate with the local client is/tmp/mysql.sock. This can cause problems because, on some versions of UNIX, anyone can delete files in the/tmp directory.

In most UNIX versions, the/TMP directory can be protected so that the file can only be deleted by all of its or superuser (root users). To do this, log in as the root user and set the sticky bit on the/tmp directory using the following command:

shell> chmod +t /tmp

By performing ls-ld/tmp, you can check to see if a sticky bit is set. If the last license character is "T", it indicates that the sticky bit is set.

Another way is to change the location where the server creates a UNIX socket file. If you do this, you should also let the client program know the location of the file. The ability to specify file locations in several different ways:

Specify the path in the global or local options file. For example, place the following line in file/etc/my.cnf:

[mysqld]
socket=/path/to/socket
[client]
socket=/path/to/socket

When you run the client program, specify the "--socket" option on the command line for Mysqld_safe.

Set the MYSQL_UNIX_PORT environment variable to the path of the UNIX socket file.

Re-compile MySQL from the source code to use a different default UNIX socket file location. When you run configure, define the file path with the--with-unix-socket-path option.

Connect to the server with the following command to test whether the new socket position is working:

shell> mysqladmin --socket=/path/to/socket version

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.