1. 程式人生 > 其它 >解決過程:wordpress建立資料庫連線時出錯;Job for httpd.service failed because the control process

解決過程:wordpress建立資料庫連線時出錯;Job for httpd.service failed because the control process

技術標籤:wordpresslinuxmysql

解決過程:wordpress建立資料庫連線時出錯;Job for httpd.service failed because the control process

問題描述

開啟wordpress個人部落格時,顯示“建立資料庫連線時出錯”。
出錯
Centos 7.6 WordPress 5.6.1 MySQL 5.7.32

原因分析

可能的原因:

  • wordpress資料庫連線資訊錯誤
    檢查 wp-config.php 連線配置
  • MySQL資料庫服務停止
  • 資料表錯誤
    由於wordpress糟糕的網路導致升級失敗,沒有注意產生的隱患
  • PHP檔案出錯

解決方案

檢查wp-config.php配置檔案好像沒啥問題。
登入MySQL試試,問題出現了

[[email protected] ~]# mysql -u wordpress -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

參考下面這篇文章的解釋:

mysql 支援 socket 和 TCP/IP 連線。連線localhost通常通過一個Unix域套接字檔案進行,一般是/tmp/mysql.sock。如果套接字檔案被刪除了,本地客戶就不能連線。/tmp 資料夾屬於臨時檔案,隨時可能被刪除。

查詢果然沒有這個檔案!

[[email protected] ~]# cd /tmp
[[email protected] tmp]# ls
041509da9c111863efdd523855c9fce2  php-cgi-72.sock                                                       ydeye_install.log
2.0.1-rOcJ42.tmp                  stargate.lock
panelSpeed.pl                     systemd-private-65750315104f41ca8ff94869ffbc7bdc-
ntpd.service-neJdHD

修改/etc/my.cnf

[[email protected] tmp]# vim /etc/my.cnf

修改前

[mysqld]
socket=/tmp/mysql.sock
[client]
socket=/tmp/mysql.sock

修改後

[mysqld]
socket=/var/lib/mysql/mysql.sock
[client]
socket=/var/lib/mysql/mysql.sock

MySQL登陸成功

重啟httpd

[[email protected] mysql]# systemctl restart httpd
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.

?檢視狀態

[[email protected] mysql]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2021-02-09 09:42:06 CST; 26s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 27587 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
  Process: 27585 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=1/FAILURE)
 Main PID: 27585 (code=exited, status=1/FAILURE)

Feb 09 09:42:06 zh httpd[27585]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
Feb 09 09:42:06 zh httpd[27585]: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
Feb 09 09:42:06 zh httpd[27585]: no listening sockets available, shutting down
Feb 09 09:42:06 zh httpd[27585]: AH00015: Unable to open logs
Feb 09 09:42:06 zh systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Feb 09 09:42:06 zh kill[27587]: kill: cannot find process ""
Feb 09 09:42:06 zh systemd[1]: httpd.service: control process exited, code=exited status=1
Feb 09 09:42:06 zh systemd[1]: Failed to start The Apache HTTP Server.
Feb 09 09:42:06 zh systemd[1]: Unit httpd.service entered failed state.
Feb 09 09:42:06 zh systemd[1]: httpd.service failed.

檢視端口占用

[[email protected] mysql]# netstat -antlp | grep 80  
tcp6       0      0 :::80                   :::*                    LISTEN      19954/httpd 

檢視程序

[[email protected] mysql]# ps -ef|grep httpd
www        436     1  0 10:08 ?        00:00:00 /www/server/apache/bin/httpd -k restart
www        437     1  0 10:08 ?        00:00:00 /www/server/apache/bin/httpd -k restart
www        438     1  0 10:08 ?        00:00:00 /www/server/apache/bin/httpd -k restart
www        826     1  0 10:09 ?        00:00:00 /www/server/apache/bin/httpd -k restart
root      1072 27224  0 10:10 pts/0    00:00:00 grep --color=auto httpd
[[email protected] mysql]# kill -9 436
[[email protected] mysql]# kill -9 437
[[email protected] mysql]# kill -9 438
[[email protected] mysql]# kill -9 826
[[email protected] mysql]# systemctl start httpd
[[email protected] mysql]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-02-09 10:11:05 CST; 5s ago

暫時可以訪問了,但好像還存在其他小問題,等等研究。