Menu

网站搬家数据库无法连接Unable to connect to the database. Main connection [MySQLi]: Access denied for user

网站维护 录入时间 2023-11-09 阅读次数 次 无双建站 wordpress翻译插件

网站搬家转移服务器是一件很正常的事,平时分分钟的事,就因为一个小小的大小写问题没注意,折腾了好半天光阴,大致流程为:

将程序及数据库转移到新服务器后,修改了数据库连接的地址及密码,程序使终显示错误,提示

CodeIgniter\Database\Exceptions\DatabaseException #8
Unable to connect to the database. Main connection [MySQLi]: Access denied for user '****'@'localhost' to database '****'
无法连接到数据库,检查数据库是否启动或者数据库配置文件不对,config/database.php

然后再次检查了数据库的权限配置包括服务器防火墙也都添加了端口,同样不会忘记端也要在云端添加,在宝塔页面都可以正常管理数据库及用Navicat连接也都显示正常,继续检查服务器

一切正常后还是无法连接,这就有点头疼了,查了很多资料还是一样,表示数据库出错。

[lighthouse@VM-12-16-centos ~]$ netstat -ntulp |grep 3306
(No info could be read for "-p": geteuid()=1001 but you should be root.)
tcp6       0      0 :::3306                 :::*                    LISTEN      -                   
[lighthouse@VM-12-16-centos ~]$ sudo systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: active (running) since Thu 2023-11-09 10:00:01 CST; 15min ago
     Docs: man:firewalld(1)
 Main PID: 16371 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─16371 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
Nov 09 10:00:01 VM-12-16-centos systemd[1]: Starting firewalld - dynamic firewall daemon...
Nov 09 10:00:01 VM-12-16-centos systemd[1]: Started firewalld - dynamic firewall daemon.
Nov 09 10:00:01 VM-12-16-centos firewalld[16371]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a future release. Please consider disabling it now.
Nov 09 10:00:02 VM-12-16-centos firewalld[16371]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be removed in a future release. Please consider disabling it now.
[lighthouse@VM-12-16-centos ~]$ sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent
Warning: ALREADY_ENABLED: 3306:tcp
success
[lighthouse@VM-12-16-centos ~]$ sudo firewall-cmd --reload
success
[lighthouse@VM-12-16-centos ~]$

没办法在经常多次折磨后,只能老老实实一次次查找原因,功失不负有心人,当我把账户,密码及数据名一个一个全部复制写入的时候突然就一切OK了,再仔细一看原来是数据库名与用户名不同,在创建数据库时,数据库名和用户名都是一样的,所以没想太多,直接用的用户名,结果就因为数据库名是小写的,而用户名里有大写,导致始终无法连接数据库


【版权声明】:本站内容来自于与互联网(注明原创稿件除外),供访客免费学习需要。如文章或图像侵犯到您的权益,请及时告知,我们第一时间删除处理!谢谢!

无双科技
如何获取外贸询盘和订单?
网站建设咨询:13534259410

经典客户案例展示

热门服务
众多企业的选择

深圳无双科技 - 专注于高端网站建设、网站设计开发、品牌网站制作

咨询电话:13534259410

售后服务:13534259410  (7×24小时)
在线 Q Q:253849310 (售前咨询)

深圳网站建设咨询
【扫一扫咨询】
  • 扫一扫 在线咨询
    无双科技官方公众号
  • 响应式客户端
    扫一扫 关注好友
体验创新服务

深圳无双科技,专注于深圳网站建设、深圳网站设计、深圳网站制作。
服务客户超3000家,一站式网站建设及推广营销解决方案提供商。
我们的价值观:诚信、坦诚、尽责、创新。期待与您合作!

您好,很高兴为您服务 ^_^