安装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. Alpha冲刺2

    前言 队名:拖鞋旅游队 组长博客:https://www.cnblogs.com/Sulumer/p/9960487.html 作业博客:https://edu.cnblogs.com/campus/ ...

  2. <Java><!!!><面试题>

    装箱 & 拆箱 public class Test03 { public static void main(String[] args) { Integer f1 = 100, f2 = 10 ...

  3. request的响应时间elapsed和超时timeout

    前言:requests发请求时,接口的响应时间,也是我们需要关注的一个点,如果响应时间太长,也是不合理的 1.获取接口请求的响应时间  r.elapsed.total_seconds() import ...

  4. tensorflow-learning-where-what-how

    这么优秀的外国小哥哥... https://github.com/machinelearningmindset/TensorFlow-Course tensorboard使用:https://gith ...

  5. cc、gcc、g++、CC的区别概括

    gcc是C编译器:g++是C++编译器:linux下cc一般是一个符号连接,指向gcc:gcc和g++都是GUN(组织)的编译器.而CC则一般是makefile里面的一个名字,即宏定义,嘿,因为Lin ...

  6. mysql数据库负载均衡

    负载均衡集群是有一组相互独立的计算机系统构成,通过常规网络或专用网络进行链接,有路由器衔接在一起,各个节点相互协作,共同负载.均衡压力,对客户端来说,整个群集可以视为一台具有超高性能的独立服务器. 实 ...

  7. winform 使用线程

    我这里写一个线程里创建一个窗体调用父窗体的方法 private void button4_Click(object sender, EventArgs e) { button4.Text = &quo ...

  8. 【Python】unittest-4

    #练习1: import random import unittest from TestCalc import TestCalcFunctions class TestSequenceFunctio ...

  9. SQL语句报错,无法绑定由多个部分组成的标识符解决

    无法绑定由多个部分组成的标识符, 表示在查询的时候使用了别名,并且查询的多个表中存在相同的字段,如果在使用该字段时不明确该字段的来源就会报这个错误. 举例: 我们有两张表,B1,B2,他们有一个共同的 ...

  10. js中call、apply和bind的区别

    在JS中,这三者都是用来改变函数的this对象的指向的,他们有什么样的区别呢.在说区别之前还是先总结一下三者的相似之处:1.都是用来改变函数的this对象的指向的.2.第一个参数都是this要指向的对 ...