本文章内容亲测有效

适用情况

腾讯云服务器重启 WordPress遇到数据库无法连接的问题。

WordPress 提示 ”建立数据库连接出现问题“

在宝塔面板中提示”数据库连接失败,请检查数据库服务是否启动!“

Phpmyadmin也提示502 Bad Gateway(已经尝试放行端口)

没有办法重启(或者使WordPress重新连接到数据库)

指令 service mysqld start 的返回结果是

● mysqld.service - LSB: start and stop MariaDB
   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2022-07-19 07:38:45 CST; 11s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 10169 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=1/FAILURE)

Jul 19 07:38:43 VM-4-16-centos systemd[1]: Starting LSB: start and stop MariaDB...
Jul 19 07:38:43 VM-4-16-centos mysqld[10169]: Starting MariaDB.220719 07:38:43 mysqld_safe Logging to '/var/log/mariad...log'.
Jul 19 07:38:43 VM-4-16-centos mysqld[10169]: 220719 07:38:43 mysqld_safe Starting mariadbd daemon with databases from...mysql
Jul 19 07:38:45 VM-4-16-centos mysqld[10169]: ./etc/rc.d/init.d/mysqld: line 264: kill: (10185) - No such process
Jul 19 07:38:45 VM-4-16-centos mysqld[10169]: ERROR!
Jul 19 07:38:45 VM-4-16-centos systemd[1]: mysqld.service: control process exited, code=exited status=1
Jul 19 07:38:45 VM-4-16-centos systemd[1]: Failed to start LSB: start and stop MariaDB.
Jul 19 07:38:45 VM-4-16-centos systemd[1]: Unit mysqld.service entered failed state.
Jul 19 07:38:45 VM-4-16-centos systemd[1]: mysqld.service failed.

报错信息

2022/07/18 22:45:34 [crit] 2258#0: *30 connect() to unix:/tmp/php-cgi-74.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: phpmyadmin, request: "POST /phpmyadmin_61e257e78f3b2635/index.php?lang=zh_cn HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi-74.sock:", host: "1.15.70.10:8888"

参考的教程有:

但这两种最后都没有解决。因为在php-fpm.conf文件下根本没有 listen = /tmp/php-cgi-73.sock  这一行
在nginx的配置文件里,也没有fastcgi_pass

因此无法替换。。。倒是在隔壁 php-fpm.conf.bak里面有。。但是改了没有效果

CSDN这篇教程下有写:

配置错误 因为 nginx 找不到php-fpm了,所以报错,一般是fastcgi_pass后面的路径配置错误了,后面可以是socket或者是ip:port

方法1:

修改php-fpm的配置文件

vim /usr/local/php/etc/php-fpm.conf   
里面的 listen = /tmp/php-fcgi.sock  改为  

listen = 127.0.0.1:9000

方法2:

修改nginx的配置文件

vim /usr/local/nginx/conf/nginx.conf     
里面的 fastcgi_pass unix:/tmp/php-fcgi.sock; 改为

fastcgi_pass 127.0.0.1:9000;

但是解决方法1、2都没有办法实现

因为1的php-fpm.conf中没有listen = /tmp/php-fcgi.sock
2中Nginx.conf没有 fastcgi_pass unix:/tmp/php-fcgi.sock


原因猜测

猜测是wordpress腾讯云轻量应用的镜像,重启后mariadb丢失了配置

即wordpress腾讯云轻量应用的镜像重启后数据库没法启动


解决方案

进入宝塔 - MySQL - 配置修改

将原有内容备份后 将下面的内容复制替换。

[client]
#password        = your_password
port                = 3306
socket                = /tmp/mysql.sock

[mysqld]
binlog_cache_size = 64K
thread_stack = 256K
join_buffer_size = 1024K
query_cache_type = 1
max_heap_table_size = 64M
port                = 3306
socket                = /tmp/mysql.sock
datadir = /www/server/data
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 128M
max_allowed_packet = 100G
table_open_cache = 128
sort_buffer_size = 768K
net_buffer_length = 4K
read_buffer_size = 768K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 32M
thread_cache_size = 64
query_cache_size = 64M
tmp_table_size = 64M
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

#skip-name-resolve
max_connections = 100
max_connect_errors = 100
open_files_limit = 65535

log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
slow_query_log=1
slow-query-log-file=/www/server/data/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on


innodb_data_home_dir = /www/server/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /www/server/data
innodb_buffer_pool_size = 256M
innodb_log_file_size = 256M
innodb_log_buffer_size = 64M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 16
innodb_write_io_threads = 16

[mysqldump]
quick
max_allowed_packet = 500M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 2M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

本方案亲测可用 来自:https://www.bt.cn/bbs/thread-88732-1-1.html

再次特别感谢宝塔以及宝塔工作人员!!!!

谢谢你们!!!

最后更新于 2023-03-05