Can T connect to the local MySQL server through Socket/tmp/mysql.sock

Source: Internet
Author: User

You cannot connect to the server through '/tmp/mysql.sock ', and the PHP standard configuration is using '/tmp/mysql.sock ', but some MySQL installation methods will

Mysql.sock in/var/lib/mysql.sock or whatever, you can fix it by modifying the/etc/my.conf file.


First of all, mysqld can't start,

I modified the value of the socket below the [mysqld] option through VIM/ETC/MY.CNF
Socket=/var/lib/mysql/mysql.sock
Ok,mysqld can be activated.

Next, the MySQL boot is not, again, VIM/ETC/MY.CNF, added the following script:

[MySQL]

Socket=/var/lib/mysql/mysql.sock

Then, mysqladmin not start, or the same, under [mysqladmin] The socket value is set to the same path
OK, it's ready to start.

Finally, when connecting with PHP, this problem occurs again.

Can ' t connect to the local MySQL server through socket '/tmp/mysql.sock ' (2)

The first thing I thought of was, in/etc/php.ini to modify the value of Mysql.default_socket, in this file, about Mysql.default_socket's

The description of the value is like this,

;  Default socket name for the local MySQL connects. If empty, uses the built-in MySQL defaults.
This value is empty at first, which means that if we don't change it, PHP will use the default values built into MySQL
So, I modified the value and set it to:

Mysql.default_socket=/var/lib/mysql/mysql.sock

Then I restart Apache, the result is invalid; reboot system, invalid result

I'm fire, PHP has to go to connect/tmp/mysql.sock, but my system is not in the path of this file, then I will give you chain

And then I did the following,

Ln-s/var/lib/mysql/mysql.sock/tmp/mysql.sock


How to Protect "/tmp/mysql.sock" from being deleted

If you have this problem, in fact anyone can delete the MySQL communication socket "/tmp/mysql.sock", on most versions of UNIX, you can

Protect your "/tmp" file system by setting the sticky (t) bit. Log in as root and do the following:

shell> chmod +t/tmp

This will protect your "/tmp" file system so that files can only be deleted by their owner or superuser (root).

You can perform ls-ld/tmp check if the sticky bit is set, if the last permission bit is T, the bit is set.

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.