Centos7 database connection using 127.0.0.1 Permission denied, using localhost to report no such file or directory

Source: Internet
Author: User

After installing the lamp environment, test the database connection.

When host uses 127.0.0.1, error: (hy000/2002): Permission denied.

Replace host with localhost, and error: sqlstate[hy000] [2002] No such file or directory.

The last discovery is because SELinux is not turned off, and it is usually enabled by default when the download is finished CentOS7.

[[Email protected] ~] # sestatus   SELinux Status:                 enabled  selinuxfs mount:                /sys/fs/selinux  selinux root directory:         /etc/selinux  Loaded policy name:             targeted  current mode :                    Enforcing  file:          enforcing  Policy MLS status:              enabled  Policy Deny_unknown status:     allowed  Max kernel policy version:      28

If you want to close temporarily, you can do this:

setenforce 0

At this point the status is as follows:

[[Email protected] ~] # sestatus   SELinux Status:                 enabled  selinuxfs mount:                /sys/fs/selinux  selinux root directory:         /etc/selinux  Loaded policy name:             targeted  current mode :                    Permissive  file:          enforcing  Policy MLS status:              enabled  Policy Deny_unknown status:     allowed  Max kernel policy version:      28    

If you want to close permanently, you can modify the configuration file/etc/selinux/config and set Selinu to Disabled.

[[Email protected] ~]#Cat/etc/selinux/config  #This file controls the state of the SELinux on the system. #selinux= can take one of these three values:#Enforcing-selinux security policy is enforced. #Permissive-selinux prints warnings instead of enforcing. #disabled-no SELinux policy is loaded. #selinux=enforcingselinux=Disabled#Selinuxtype= can take one of three the values:#targeted-targeted processes is protected,#Minimum-modification of targeted policy.   Only selected processes is protected. #Mls-multi level Security protection. selinuxtype=targeted

Modifying the configuration file can also be done by executing the following command:

After the modification is complete, save the reboot and reboot after the following status:

[[Email protected] ~] # sestatus   SELinux Status:                 disabled  

The article my pro-test effective.

Posts reprinted: 48265445

Centos7 database connection using 127.0.0.1 Permission denied, using localhost to report no such file or directory

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.