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是启用状态。

[[email protected] ~]# 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

此时状态如下:

[[email protected] ~]# 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。

[[email protected] ~]# 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 

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

[[email protected] ~]# sestatus
SELinux status:                 disabled  

文章本人亲测有效。

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

原文地址:https://www.cnblogs.com/clubs/p/9308845.html

时间: 2024-07-30 18:50:20

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

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 启动失败,日志里面报错信息如下: Starting nginx: nginx: [emerg] bind() to 0.0.0.0:8088 failed (13: Permission denied) 权限拒绝,经检查发现是开启selinux 导致的. 直接关闭 getenforce   这个命令可以查看当前是否开

解决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 (label: homebrew.mxcl.nginx) ==> Successfully started nginx (label: homebrew.mxcl.nginx) 但是实际上没启动成功,查看下错误日志 tail -n 10 /usr/local/var/log/nginx/error.l

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

连接数据库报错:“SQLSTATE[HY000] [2002] No such file or directory”. 出现这个问题的原因是PDO无法找到mysql.sock或者mysqld.sock.  解决方法1:找到相应的.sock文件,并设置php.ini文件中的pdo_mysql.default_socket的值为.sock文件的路径. pdo_mysql.default_socket= /tmp/mysqld.sock 然后重启Apache,或者nginx下重启php-fpm即可.

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

1.cnmp安装失败 2.提示如下: bogon:node_modules liangjingming$ sudo npm install cnpm -g --registry=https://registry.npm.taobao.org Password: /usr/local/lib └── (empty) npm ERR! Darwin 16.4.0 npm ERR! argv "/usr/local/Cellar/node/7.8.0/bin/node" "/usr

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

今天晕了半天了,搞了个git工程到github上,以为很简单,因为之前也弄过,那知道搞了大半天都搞不好,一直报如下错误 D:\javawork\ee-0.0.1-SNAPSHOT>git push -u origin masterWarning: Permanently added the RSA host key for IP address '192.30.252.130' to the list of known hosts.Permission denied (publickey).fa

vue报错 Module not found: Error: Cannot resolve 'file' or 'directory'

炸了,我好写sell而组件,直接就用了,我的天哪 看你的写了吗,就用: Module not found: Error: Cannot resolve 'file' or 'directory' 页另一种错误,按这种情况我没遇到:http://www.mamicode.com/info-detail-1564042.html vue报错 Module not found: Error: Cannot resolve 'file' or 'directory'

github提交代码时,报permission denied publickey

在像github提交代码时,报permission denied publickey. 查找了一下,可能是因为github的key失效了. 按照以下步骤,重新生成key. ssh-keygen 一路默认下去. 会在home目录的.ssh文件夹下生成两个文件: id_rsa 和id_rsa.pub id_rsa是私钥,需要保存在本地的.id_rsa.pub是公钥,需要上传到github. 在github的右上角edit your profile 里找到ssh key,然后add ssh key,把

Redis 2.8.18 安装报错 error: jemalloc/jemalloc.h: No such file or directory

Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API. 本文为大家讲解的是Redis 2.8.18 安装报错 error: jemalloc/jemalloc.h: No such file or directory解决方法,感兴趣的同学参考下. 错误描述 安装Redis 2.8.18时报错: zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or

Eclipse远程连接hadoop时 报 Permission denied:

用Eclipse远程连接hadoop时报org.apache.hadoop.security.AccessControlException: Permission denied: user=DrWho, access=READ_EXECUTE, inode="system":hadoop:supergroup:rwx-wx-wx错误,解决方法: 在hdfs-site.xml 中取消权限校验,即加入以下配置: <property>    <name>dfs.per