安装lamp环境后,测试数据库连接。

当host使用127.0.0.1时,报错:(HY000/2002): Permission denied。

把host换成localhost后,又报错:SQLSTATE[HY000] [2002] No such file or directory。

最后发现是因为没有关闭selinux,通常情况下载安装完CentOS7后,默认情况下SElinux是启用状态。

[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

如果要临时关闭,可以执行:

setenforce 0

此时状态如下:

[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

如果要永久关闭,可以修改配置文件/etc/selinux/config,将SELINU置为disabled。

[root@rdo ~]# cat /etc/selinux/config   

# This file controls the state of 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=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

修改该配置文件也可以执行下面的命令来完成:

sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config 

修改完成后,保存重启,重启后状态如下:

[root@rdo ~]# sestatus
SELinux status: disabled

文章本人亲测有效。

文章转载:https://blog.csdn.net/eclothy/article/details/48265445

centos7数据库连接使用127.0.0.1报permission denied,使用localhost报No such file or directory的更多相关文章

  1. 解决nginx报错:nginx: [emerg] bind() to 0.0.0.0:8088 failed (13: Permission denied)

    报错描述: nginx: [emerg] bind() to 0.0.0.0:8088 failed (13: Permission denied) 通过ansible远程给主机更换端口并重新启动ng ...

  2. Ubuntu nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)

    在Ubuntu 12中启动刚安装好的Nginx,报错: nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied) 原因如下: ...

  3. Starting nginx: nginx: [emerg] bind() to 0.0.0.0:8088 failed (13: Permission denied) nginx 启动失败

     Starting nginx: nginx: [emerg] bind() to 0.0.0.0:8088 failed (13: Permission denied)     nginx 启动失败 ...

  4. 解决Mac nginx问题 [emerg] 54933#0: bind() to 0.0.0.0:80 failed (13: Permission denied)

    brew services restart nginx Stopping nginx... (might take a while) ==> Successfully stopped nginx ...

  5. TP连接数据库报错:SQLSTATE[HY000] [2002] No such file or directory

     连接数据库报错:“SQLSTATE[HY000] [2002] No such file or directory”. 出现这个问题的原因是PDO无法找到mysql.sock或者mysqld.soc ...

  6. git push是报Permission denied (publickey)错误解决

    今天晕了半天了,搞了个git工程到github上,以为很简单,因为之前也弄过,那知道搞了大半天都搞不好,一直报如下错误 D:\javawork\ee-0.0.1-SNAPSHOT>git pus ...

  7. cnmp安装失败,报错npm ERR! enoent ENOENT: no such file or directory,

    1.cnmp安装失败 2.提示如下: bogon:node_modules liangjingming$ sudo npm install cnpm -g --registry=https://reg ...

  8. github提交代码时,报permission denied publickey

    在像github提交代码时,报permission denied publickey. 查找了一下,可能是因为github的key失效了. 按照以下步骤,重新生成key. ssh-keygen 一路默 ...

  9. Windows下使用ssh-add报错 Error connecting to agent: No such file or directory

    Windows下使用ssh-add报错 Error connecting to agent: No such file or directory 环境信息 操作系统:windows 10 终端:Win ...

随机推荐

  1. PC或者手机上实现相机拉近和旋转

    using System.Collections;using System.Collections.Generic;using UnityEngine;using System; //[Seriali ...

  2. jquery转换json对象为字符串

    jquery转换json对象为字符串 JSON.stringify(jsonObject),可用于单个JSON对象,也可用于JSON数组 alert(JSON.stringify(jsonObject ...

  3. Effective Java (ENUM篇)

    我们存放一些静态变量,像是一些变量和设置,等等等等,我们尽量使用ENUM,因为ENUM是不可实例化和继承的,所以他很安全,它是在程序一开始运行的时候进行一些编译,修改ENUM不需要再次编译. 在什么时 ...

  4. SDK Manager的使用

    前言:SDK Manager就是一个Android软件开发工具包管理器,就像一个桥梁,连通本地和服务器,从服务器下载安卓开发所需工具到本地. 1.在android sdk 安装目录下,有一个SDK M ...

  5. zabbix 监控java通用

    监控工具 jstat jstack http://www.blogjava.net/jjshcc/archive/2014/03/05/410655.html https://www.cnblogs. ...

  6. 2019-03-26-day019-面向对象耦合与组合

    作业 #对象的耦合 class Circle: def __init__(self,r): self.r = r def area(self): return 3.14*self.r**2 def p ...

  7. Python基础2--Python简单数据类型

    python简单数据类型 1 list list的创建,使用[] a_list = [‘a’, ’b’, ‘c’] print a_list print a_list[0] #a 如果去list的最后 ...

  8. 九度OJ1049题-去特定字符(和1111题特别像)

    题目1049:字符串去特定字符 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:11329 解决:5169 题目描述: 输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果. 输入: ...

  9. mac上不了网

    不知怎么回事勾选了socks代理导致ping的通但打不开网页软件登不了

  10. 如何更改Apache的根目录指向

    更改Apache的默认网站根目录地址方法如下: 0,先找到主目录下的apache文件,然后进行下面操作 1.找到 DocumentRoot “X:/Apache/htdocs” 将“X:/Apache ...