PHP访问数据库出现Access denied for user ‘root’@‘IP地址’

·LAMP环境下

网上的方法测试均无效,之后一次偶然本地登陆出现警告:Warning: World-writable config file '文件路径' is ignored,上网查询后是由于该文件任何人都可以修改,mysql防止有人恶意修改设置,忽略相关配置文件。相关链接

解决方法很简单,去除其他人的写入权限即可,假设报错为:Warning: World-writable config file ’/etc/my.cnf‘ is ignored

更改/etc/my.cnf的权限为644

1 cd /etc
2 sudo chmod 644 my.cnf

chmod:

  chmod xyz分别代表给user,group,other设置x,y,z权限

  xyz数字分别是:4:写入,2:读取,1:执行

  chmod 644代表给user设置6(4+2,rw-),group设置4(r--),other设置4(r--)

  之后再次本地登录mysql不再警告,随后远程php正常访问mysql

-------------------------------------------------

其他发布位置:

CSDN

posted @ 2022-03-23 20:47  忠诚的女仆罗斯福  阅读(297)  评论(0编辑  收藏  举报