安装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. 1.横向滚动条,要设置两个div包裹. 2. 点击切换视频或者图片. overflow . overflow-x

    1.横向滚动条. div.1 > div.2 > img img  img 第一: 设置 div.1 一个固定的宽度 和高度  . 例如宽度 700px;  高度是 120px; 设置 o ...

  2. 校验总结:校验是否是中英文等等(1.正则校验 2.hibernate volidator)

    1.正则校验 import java.util.regex.Matcher;import java.util.regex.Pattern; public class Validation { //-- ...

  3. HDU 6055 17多校 Regular polygon(计算几何)

    Problem Description On a two-dimensional plane, give you n integer points. Your task is to figure ou ...

  4. 【Python】多进程2

    #练习:测试单进程和多进程执行效率 import multiprocessing import time def m1(x): time.sleep(0.01) return x * x if __n ...

  5. 获取Map的key和value的两种方法

    //使用迭代器,获取key; /*Iterator<String> iter = map.keySet().iterator(); while(iter.hasNext()){ Strin ...

  6. Power BI十大视觉效果,知多少?

    Power BI十大视觉效果: 图表滑块 响应式布局 一键更改方差计算 一键排序 我们的最爱:小倍数! 瀑布图中的轴断裂 层次表(完全响应) HICHERT博士的IBCS®原生支持 分段图表 - 可视 ...

  7. 【转载】 强化学习(二)马尔科夫决策过程(MDP)

    原文地址: https://www.cnblogs.com/pinard/p/9426283.html ------------------------------------------------ ...

  8. 密码安全存储——PBKDF2、bcrypt、scrypt

    密码用单向哈希存储保证了数据库被脱后用户密码的安全. 由于彩虹表这种攻击方式的存在,一般认为md5,SHA1等单向算法的安全性是不够的.那如何选择合适的加密算法? 下面介绍业界几种高强度单向哈希算法, ...

  9. POJO,JaveBean,VO,DTO

    POJO - POJO(Plain Ordinary Java Object)简单的Java对象,实际就是普通JavaBeans,是为了避免和EJB混淆所创造的简称. 使用POJO名称是为了避免和EJ ...

  10. 归并排序merge_sort

    将区间递归分解,直到区间只有2个元素,然后比较大小,排序,等递归回来的时候就将排序好的子区间再排序合并....一直排序合并,最后就排序完成了. (可以做范围大的逆序数的题) #include < ...