最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】WordPress网站crifan.com出错:建立数据库连接时出错 这意味着您在wp-config.php文件中指定的用户名和密码信息不正确

WordPress crifan 1862浏览 0评论
20200822
又遇到了:
https://www.crifan.com/wp-admin/
出错:
建立数据库连接时出错
这意味着您在wp-config.php文件中指定的用户名和密码信息不正确,或我们未能在localhost联系到数据库服务器。这可能意味着您主机的数据库服务器未在运行。
* 您确定用户名和密码正确吗?
* 您确定输入的主机名正确吗?
* 您确定数据库服务器在运行吗?
如果您不明白这些意味着什么,您应该联系您的主机提供商。如果您仍需要帮助,请访问WordPress支持论坛。
参考:
【已解决】crifan.com访问出错无法打开:因为无法与服务器建立安全连接
去看看
[root@crifan ~]# crontab -l
*/20 * * * * /sbin/ntpdate -u 
pool.ntp.org
 > /dev/null 2>&1
21 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null
[root@crifan ~]# service mysqld status
MySQL running (5381)                                       [  OK  ]
想确认数据库正常,尝试重启mysqld
[root@crifan ~]# service mysqld restart
Shutting down MySQL.....................The server quit wit[FAILED]ating PID file (/data/mysql/mysql.pid).
Failed to stop running server, so refusing to try to start.[FAILED]
结果是出错了。
去看了看剩余空间
[root@crifan ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        79G   75G     0 100% /
devtmpfs        1.9G     0  1.9G   0% /dev
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           1.9G  193M  1.7G  11% /run
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
tmpfs           379M     0  379M   0% /run/user/0
果然是:空间不够了。。。
去删除log日志
参考
【已解决】CentOS中mysql的bin的log日志文件占用太多空间
[root@crifan mysql]# mysql -u root -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
等不进mysql
删除单个log:
# rm -f mysql-bin.000478
重启mysql试试
[root@crifan mysql]# service mysqld restart
MySQL server process #5381 is not running!                 [FAILED]
Starting MySQL...                                          [  OK  ]
即可正常启动。
网站即可打开,但是需要升级数据库:
https://www.crifan.com/wp-admin/upgrade.php?step=1&backto=%2Fwp-admin%2F
升级完成
您的WordPress数据库已成功升级!
继续
即可正常显示登录页面:
然后参考:
【已解决】CentOS中mysql的bin的log日志文件占用太多空间
继续登录mysql,去设置bin的log
[root@crifan mysql]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 437
Server version: 5.7.26-log MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> SET GLOBAL expire_logs_days = 1;
Query OK, 0 rows affected (0.00 sec)

MySQL [(none)]> SET GLOBAL max_binlog_size = 209715200;
Query OK, 0 rows affected (0.00 sec)

MySQL [(none)]> PURGE BINARY LOGS TO 'mysql-bin.000494';
Query OK, 0 rows affected (0.07 sec)

MySQL [(none)]> 
Control+Z 退出看看
[root@crifan mysql]# ls -lh
total 603M
...
drwxr-x--- 2 mysql mysql 4.0K May  9  2019 mysql
-rw-r----- 1 mysql mysql 390M Aug 22 08:45 mysql-bin.000494
-rw-r----- 1 mysql mysql 5.5M Aug 22 08:51 mysql-bin.000495
-rw-r----- 1 mysql mysql   38 Aug 22 08:50 mysql-bin.index
-rw-r----- 1 mysql mysql 2.0M Aug 22 08:51 mysql-error.log
...
10多G的bign的log就清除掉了。
现在剩余空间就有很多了:
[root@crifan mysql]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        79G   59G   16G  79% /
devtmpfs        1.9G     0  1.9G   0% /dev
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           1.9G  193M  1.7G  11% /run
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
tmpfs           379M     0  379M   0% /run/user/0
即:
  • Avail是=可用:16G
    • 已使用:79%
【总结】
以后如果WordPress的页面报错:
建立数据库连接时出错
这意味着您在wp-config.php文件中指定的用户名和密码信息不正确,或我们未能在localhost联系到数据库服务器。这可能意味着您主机的数据库服务器未在运行。
-》很可能是:mysql停止了
-》背后原因:很可能是 剩余空间是0 没空间了
可以通过:
df -h
确认是否是此原因。
如果是,那可能是mysql的bin的log日志太多而占用的空间
可以通过:
cd /data/mysql
ls -lh
确认是否是:
有很多个 mysql-bin.000xxx,且每个都很大(比如1G)
如果是,则去:
(1)先删掉最旧 最早的一个
rm -f mysql-bin.000478
(2)重启mysql,确保mysql运行
service mysqld restart
(3)登入mysql,设置参数 + 清理bin的log
mysql -u root -p
最多保存1天:
SET GLOBAL expire_logs_days = 1;
单个bin的log最大文件大小是200M
SET GLOBAL max_binlog_size = 209715200;
清除掉所有的bin的log:
PURGE BINARY LOGS TO 'mysql-bin.000494';
其中:
  • mysql-bin.000494
    • 是最新的,最近产生的bin的log的文件名

转载请注明:在路上 » 【已解决】WordPress网站crifan.com出错:建立数据库连接时出错 这意味着您在wp-config.php文件中指定的用户名和密码信息不正确

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.176 seconds, using 22.18MB memory