Centos7 database connection using 127.0.0.1 Report permission denied, use localhost to report no such file or directory__ database

Source: Internet
Author: User

After installing the lamp environment, test the database connection.

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

After replacing the host with localhost, it also complains: sqlstate[hy000] [2002] No such file or directory.


The final discovery is that SELinux is not turned off, and SELinux is enabled by default after CentOS7 is installed.

[Root@rdo ~]# sestatus  
SELinux Status:                 enabled  
SELINUXFS mount:                /sys/fs/selinux SELinux  
Root Directory:         /etc/selinux  
Loaded policy name:             targeted current  
mode:                   enforcing  
mode from Config file:          enforcing  
Policy MLS status:              enabled  
Policy deny_unknown status:     allowed  
Max Kernel policy version:      28
If you want to temporarily close, you can perform:

Setenforce 0
At this point the status is as follows:

[Root@rdo ~]# sestatus  
SELinux Status:                 enabled  
SELINUXFS mount:                /sys/fs/selinux SELinux  
Root Directory:         /etc/selinux  
Loaded policy name:             targeted current  
mode:                   permissive  
mode from Config file:          enforcing  
Policy MLS status:              enabled  
Policy deny_unknown status:     allowed  
Max Kernel policy version:      28    
If you want to shut down permanently, you can modify the profile/etc/selinux/config to Selinu to disabled.

[Root@rdo ~]# cat/etc/selinux/config # This file controls to the state of SELinux on the   
  
system.  
# selinux= can take one of these three values:  
#     Enforcing-selinux The security policy is enforced.  
#     Permissive-selinux Prints warnings instead of enforcing.  
#     Disabled-no SELinux policy is loaded.  
#SELINUX =enforcing  
selinux=disabled  
# selinuxtype= can take one of three two values:  
#     targeted- Targeted processes are protected,  
#     Minimum-modification of targeted policy. Only selected processes are 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 status as follows:

[Root@rdo ~]# sestatus  
SELinux Status:                 disabled  

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.