Linux · 2021年7月22日

docker版wordpress出现数据库连接错误解决办法

因为小主机内存小,经常内存占满,我就采用重启的方法,导致重启过后,wordpress站点出现数据库连接错误。

查看wp-config.php后,因为是docker版wordpress 所以数据库IP都没有变化,不是wordpress配置文件的锅。

排查mysql方面

一、查看mysql的docker logs日志

docker logs [container ID]

发现如下错误:

2021-07-22T13:03:25.793711Z 10 [ERROR] mysqld: Table './wordpress/wp_options' is marked as crashed and should be repaired
2021-07-22T13:03:25.794114Z 9 [ERROR] mysqld: Table './wordpress/wp_options' is marked as crashed and should be repaired

二、修复mysql 错误

1.进入mysql 容器

docker exec -it [container ID] /bin/bash

2.进入数据库

mysql -u root -p wordpress

提示输入密码

3.查看错误原因

mysql> select * from wp_options;
ERROR 145 (HY000): Table './wordpress/wp_options' is marked as crashed and should be repaired

4.修复错误

mysqlcheck -u root -p wordpress --auto-repair

5.自动修复完成,wordpress恢复正常。

root@1ab246070757:/# mysqlcheck -u root -p wordpress --auto-repair
Enter password:
wordpress.wp_actionscheduler_actions OK
wordpress.wp_actionscheduler_claims OK
wordpress.wp_actionscheduler_groups OK
wordpress.wp_actionscheduler_logs OK
wordpress.wp_commentmeta OK
wordpress.wp_comments
warning : 1 client is using or hasn't closed the table properly
status : OK
wordpress.wp_links OK
wordpress.wp_mailchimp_carts OK
wordpress.wp_mailchimp_jobs OK
wordpress.wp_options
warning : Table is marked as crashed
warning : 78 clients are using or haven't closed the table properly
error : Found 586 keys of 587
error : Corrupt
wordpress.wp_postmeta
warning : 14 clients are using or haven't closed the table properly
status : OK
wordpress.wp_posts
warning : 17 clients are using or haven't closed the table properly
status : OK
wordpress.wp_term_relationships
warning : 8 clients are using or haven't closed the table properly
status : OK
wordpress.wp_term_taxonomy
warning : 7 clients are using or haven't closed the table properly
status : OK
wordpress.wp_termmeta
warning : 1 client is using or hasn't closed the table properly
status : OK
wordpress.wp_terms
warning : 1 client is using or hasn't closed the table properly
status : OK
wordpress.wp_usermeta
warning : 14 clients are using or haven't closed the table properly
status : OK
wordpress.wp_users
warning : 1 client is using or hasn't closed the table properly
status : OK
wordpress.wp_wc_admin_note_actions OK
wordpress.wp_wc_admin_notes OK
wordpress.wp_wc_category_lookup OK
wordpress.wp_wc_customer_lookup OK
wordpress.wp_wc_download_log OK
wordpress.wp_wc_order_coupon_lookup OK
wordpress.wp_wc_order_product_lookup OK
wordpress.wp_wc_order_stats OK
wordpress.wp_wc_order_tax_lookup OK
wordpress.wp_wc_product_meta_lookup OK
wordpress.wp_wc_reserved_stock OK
wordpress.wp_wc_tax_rate_classes OK
wordpress.wp_wc_webhooks OK
wordpress.wp_woocommerce_api_keys OK
wordpress.wp_woocommerce_attribute_taxonomies OK
wordpress.wp_woocommerce_downloadable_product_permissions OK
wordpress.wp_woocommerce_log OK
wordpress.wp_woocommerce_order_itemmeta OK
wordpress.wp_woocommerce_order_items OK
wordpress.wp_woocommerce_payment_tokenmeta OK
wordpress.wp_woocommerce_payment_tokens OK
wordpress.wp_woocommerce_sessions OK
wordpress.wp_woocommerce_shipping_zone_locations OK
wordpress.wp_woocommerce_shipping_zone_methods OK
wordpress.wp_woocommerce_shipping_zones OK
wordpress.wp_woocommerce_tax_rate_locations OK
wordpress.wp_woocommerce_tax_rates OK

Repairing tables
wordpress.wp_options
info : Wrong bytesec: 0- 0- 0 at 836064; Skipped
warning : Number of rows changed from 587 to 582
status : OK