centos7数据库连接使用127.0.0.1报permission denied,使用localhost报No such file or directory
安装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的更多相关文章
- 解决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 ...
- 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) 原因如下: ...
- 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 启动失败 ...
- 解决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 ...
- TP连接数据库报错:SQLSTATE[HY000] [2002] No such file or directory
连接数据库报错:“SQLSTATE[HY000] [2002] No such file or directory”. 出现这个问题的原因是PDO无法找到mysql.sock或者mysqld.soc ...
- git push是报Permission denied (publickey)错误解决
今天晕了半天了,搞了个git工程到github上,以为很简单,因为之前也弄过,那知道搞了大半天都搞不好,一直报如下错误 D:\javawork\ee-0.0.1-SNAPSHOT>git pus ...
- 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 ...
- github提交代码时,报permission denied publickey
在像github提交代码时,报permission denied publickey. 查找了一下,可能是因为github的key失效了. 按照以下步骤,重新生成key. ssh-keygen 一路默 ...
- 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 ...
随机推荐
- ASP.NET使用文件上传控件上传图片
ASPX代码 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default. ...
- TensorFlow函数:tf.lin_space
函数:tf.lin_space 别名: tf.lin_space tf.linspace lin_space( start, stop, num, name=None ) 参见指南:生成常量,序列和随 ...
- rgba 和 opacity 的对比.
rgba 中 的 a 指的是透明度: 1. rgba 的 设置的 透明度 不会被子级 元素继承; opacity 设置的透明度会被子级元素继承 . 因此 ,有时候 使用 rgba 会比 opa ...
- python 3.x 字典的11种方法
python 3.x 字典的11种方法2017年11月25日 01:02:11 Milton-Long 阅读数:535 标签: python python字典方法 更多个人分类: python-学习之 ...
- java学习笔记12(final ,static修饰符)
final: 意思是最终的,是一个修饰符,有时候一个功能类被开发好了,不想被子类重写就用final定义, 用final修饰的最终数据成员:如果一个类的数据成员用final修饰符修饰,则这个数据成员就被 ...
- 由于php环境时间与北京时间相差7个小时
故在设置当前时间时候需要加上 date_default_timezone_set('prc'); 或者 在php.ini里面设置date.timezone=prc
- 4--Selenium环境准备---chromedriver.exe 与chrome版本匹配
0.jdk8 和eclipse 4.6 https://www.eclipse.org/downloads/packages/release/neon/3 1.selenium-server-stan ...
- Xposed Hook & Anti-hook
一点简单记录. xposed原理包括将hook的method转为Native.因此可检测如下: for (ApplicationInfo applicationInfo : applicationIn ...
- 九度OJ1451题-信封错装
题目1451:不容易系列之一 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:2004 解决:1210 题目描述: 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了!做好“ ...
- 九度OJ1049题-去特定字符(和1111题特别像)
题目1049:字符串去特定字符 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:11329 解决:5169 题目描述: 输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果. 输入: ...