{"id":6722,"date":"2026-03-21T14:03:52","date_gmt":"2026-03-21T06:03:52","guid":{"rendered":"https:\/\/topfreetheme.com\/?p=6722"},"modified":"2026-03-21T14:10:11","modified_gmt":"2026-03-21T06:10:11","slug":"wordpress%e6%8a%a5%e9%94%99-error-establishing-a-database-connection","status":"publish","type":"post","link":"https:\/\/topfreetheme.com\/?p=6722","title":{"rendered":"WordPress\u62a5\u9519 Error establishing a database connection"},"content":{"rendered":"\n<p>wordpress\u7f51\u7ad9\u8bbf\u95ee\u65f6\u51fa\u73b0\u201cError establishing a database connection\u201d<\/p>\n\n\n\n<p>\u8fd9\u662fWordPress\u6700\u5e38\u89c1\u7684\u6570\u636e\u5e93\u8fde\u63a5\u5931\u8d25\u9519\u8bef\uff0c\u610f\u601d\u662f\uff1a\u7f51\u7ad9\u65e0\u6cd5\u8fde\u63a5\u5230MySQL\/MariaDB\u6570\u636e\u5e93\u3002<\/p>\n\n\n\n<p>\u4e00\u3001\u6838\u5fc3\u539f\u56e0(99%\u90fd\u662f\u8fd94\u7c7b)<\/p>\n\n\n\n<p>\u6570\u636e\u5e93\u914d\u7f6e\u4fe1\u606f\u9519\u8bef(wp-config.php\u91cc\u7684\u8d26\u53f7\/\u5bc6\u7801\/\u4e3b\u673a\u540d\u5199\u9519)\u2192\u6700\u5e38\u89c1<\/p>\n\n\n\n<p>\u6570\u636e\u5e93\u670d\u52a1\u5b95\u673a\/\u672a\u542f\u52a8(MySQL\/MariaDB\u6302\u4e86)<\/p>\n\n\n\n<p>\u6570\u636e\u5e93\u88ab\u5220\u9664\/\u4e0d\u5b58\u5728<\/p>\n\n\n\n<p>\u7f51\u7ad9\u6d41\u91cf\u66b4\u589e\/\u6570\u636e\u5e93\u635f\u574f(\u670d\u52a1\u5668\u8d44\u6e90\u8017\u5c3d)<\/p>\n\n\n\n<p>\u4e8c\u3001\u4e00\u6b65\u4e00\u6b65\u89e3\u51b3(\u4ece\u6700\u7b80\u5355\u5230\u6700\u590d\u6742)<\/p>\n\n\n\n<p>1.\u68c0\u67e5wp-config.php\u6570\u636e\u5e93\u914d\u7f6e(90%\u7684\u95ee\u9898\u5728\u8fd9\u91cc)<\/p>\n\n\n\n<p>\u7528FTP\/\u6587\u4ef6\u7ba1\u7406\u5668\u6253\u5f00\u7f51\u7ad9\u6839\u76ee\u5f55\uff0c\u627e\u5230wp-config.php\uff0c\u68c0\u67e5\u8fd94\u9879\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u6570\u636e\u5e93\u540d\ndefine( 'DB_NAME', 'wodepress' );\n\n\/\/ \u6570\u636e\u5e93\u7528\u6237\u540d\ndefine( 'DB_USER', 'wodepress' );\n\n\/\/ \u6570\u636e\u5e93\u5bc6\u7801\ndefine( 'DB_PASSWORD', '123456' );\n\n\/\/ \u6570\u636e\u5e93\u4e3b\u673a\uff08\u7edd\u5927\u591a\u6570\u586b localhost\uff09\ndefine( 'DB_HOST', 'localhost' );<\/code><\/pre>\n\n\n\n<p>\u6b63\u786e\u505a\u6cd5\uff1a<\/p>\n\n\n\n<p>\u53bb\u4f60\u7684\u4e3b\u673a\u9762\u677f(\u5b9d\u5854\u3001cPanel\u3001\u4e3b\u673a\u5546\u540e\u53f0)\u590d\u5236\u51c6\u786e\u7684\u6570\u636e\u5e93\u540d\u3001\u7528\u6237\u3001\u5bc6\u7801<\/p>\n\n\n\n<p>\u7c98\u8d34\u8fdb\u53bb\uff0c\u4e0d\u8981\u6709\u7a7a\u683c\u3001\u4e0d\u8981\u5199\u9519\u5b57\u7b26<\/p>\n\n\n\n<p>\u6570\u636e\u5e93\u4e3b\u673a\uff1a\u672c\u5730\u670d\u52a1\u5668\u586blocalhost;\u4e91\u6570\u636e\u5e93\/\u72ec\u7acb\u6570\u636e\u5e93\u670d\u52a1\u5668\u586b\u670d\u52a1\u5546\u7ed9\u7684IP<\/p>\n\n\n\n<p>2.\u786e\u8ba4\u6570\u636e\u5e93\u7528\u6237\u62e5\u6709\u8bbf\u95ee\u6743\u9650<\/p>\n\n\n\n<p>\u5f88\u591a\u4eba\u7528\u6237\u540d\u5bc6\u7801\u90fd\u5bf9\uff0c\u4f46\u6ca1\u7ed9\u6743\u9650\uff0c\u4f9d\u7136\u8fde\u4e0d\u4e0a\u3002<\/p>\n\n\n\n<p>\u89e3\u51b3\uff1a<\/p>\n\n\n\n<p>\u5b9d\u5854\/\u4e3b\u673a\u9762\u677f\u2192\u6570\u636e\u5e93\u7ba1\u7406<\/p>\n\n\n\n<p>\u627e\u5230\u4f60\u7684\u6570\u636e\u5e93\u2192\u7ed9\u5bf9\u5e94\u7528\u6237\u6388\u4e88\u5168\u90e8\u6743\u9650<\/p>\n\n\n\n<p>\u91cd\u542f\u6570\u636e\u5e93\u670d\u52a1<\/p>\n\n\n\n<p>3.\u6570\u636e\u5e93\u670d\u52a1\u672a\u542f\u52a8(\u670d\u52a1\u5668\u73af\u5883\u95ee\u9898)<\/p>\n\n\n\n<p>\u5982\u679c\u662f\u81ea\u5df1\u642d\u5efa\u7684\u670d\u52a1\u5668(\u963f\u91cc\u4e91\/\u817e\u8baf\u4e91\/\u72ec\u7acb\u670d\u52a1\u5668)\uff0cMySQL\u53ef\u80fd\u6302\u4e86\u3002<\/p>\n\n\n\n<p>Linux\u670d\u52a1\u5668\u91cd\u542f\u547d\u4ee4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># CentOS\nsystemctl restart mysqld\n# \u6216\nsystemctl restart mariadb\n\n# Ubuntu\/Debian\nsystemctl restart mysql<\/code><\/pre>\n\n\n\n<p>\u91cd\u542f\u540e\u5237\u65b0\u7f51\u7ad9\u5373\u53ef\u3002<\/p>\n\n\n\n<p>4.\u6570\u636e\u5e93\u540d\u79f0\u9519\u8bef\/\u6570\u636e\u5e93\u88ab\u5220\u9664<\/p>\n\n\n\n<p>\u5982\u679cwp-config.php\u91cc\u7684\u6570\u636e\u5e93\u540d\u6839\u672c\u4e0d\u5b58\u5728\uff0c\u4e00\u5b9a\u4f1a\u62a5\u9519\u3002<\/p>\n\n\n\n<p>\u68c0\u67e5\uff1a<\/p>\n\n\n\n<p>\u53bb\u9762\u677f\u770b\u6570\u636e\u5e93\u5217\u8868<\/p>\n\n\n\n<p>\u786e\u4fdd\u540d\u5b57\u548c\u914d\u7f6e\u6587\u4ef6\u5b8c\u5168\u4e00\u81f4<\/p>\n\n\n\n<p>5.\u6570\u636e\u5e93\u635f\u574f(\u5c11\u89c1\u4f46\u4f1a\u53d1\u751f)<\/p>\n\n\n\n<p>WordPress\u81ea\u5e26\u4fee\u590d\u5de5\u5177\uff0c\u6253\u5f00wp-config.php\u52a0\u5165\u4e00\u884c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>define('WP_ALLOW_REPAIR', true);<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u8bbf\u95ee\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wodepress.com\/wp-admin\/maint\/repair.php<\/code><\/pre>\n\n\n\n<p>\u70b9\u51fb\u4fee\u590d\u6570\u636e\u5e93\uff0c\u4fee\u590d\u5b8c\u52a1\u5fc5\u5220\u9664\u521a\u624d\u52a0\u7684\u90a3\u884c\u4ee3\u7801\u3002<\/p>\n\n\n\n<p>6.\u4e3b\u673a\u5546\u670d\u52a1\u5668\u95ee\u9898(\u65e0\u9700\u4f60\u64cd\u4f5c)<\/p>\n\n\n\n<p>\u5982\u679c\u4ee5\u4e0a\u90fd\u6ca1\u95ee\u9898\uff0c\u5c31\u662f\u4e3b\u673a\u5546\u7684\u6570\u636e\u5e93\u670d\u52a1\u5668\u5b95\u673a\u4e86\u3002<\/p>\n\n\n\n<p>\u7b49\u5f855~20\u5206\u949f\uff0c\u6216\u8054\u7cfb\u4e3b\u673a\u5546\u5ba2\u670d\u3002<\/p>\n\n\n\n<p>\u4e09\u3001\u5feb\u901f\u6392\u67e5\u6e05\u5355(\u590d\u5236\u5bf9\u7167)<\/p>\n\n\n\n<p>wp-config.php\u6570\u636e\u5e93\u540d\u3001\u7528\u6237\u3001\u5bc6\u7801\u5b8c\u5168\u6b63\u786e<\/p>\n\n\n\n<p>\u6570\u636e\u5e93\u7528\u6237\u62e5\u6709\u6743\u9650<\/p>\n\n\n\n<p>DB_HOST\u662flocalhost\u6216\u6b63\u786e\u7684\u6570\u636e\u5e93\u5730\u5740<\/p>\n\n\n\n<p>MySQL\/MariaDB\u670d\u52a1\u6b63\u5728\u8fd0\u884c<\/p>\n\n\n\n<p>\u6570\u636e\u5e93\u771f\u5b9e\u5b58\u5728<\/p>\n\n\n\n<p>\u5c1d\u8bd5\u4fee\u590d\u6570\u636e\u5e93<\/p>\n\n\n\n<p>\u56db\u3001\u6700\u5e38\u89c1\u7684\u5751(\u65b0\u624b\u5fc5\u770b)<\/p>\n\n\n\n<p>\u5bc6\u7801\u91cc\u6709\u7279\u6b8a\u7b26\u53f7\uff0c\u76f4\u63a5\u5199\u5728\u914d\u7f6e\u91cc\u6ca1\u52a0\u5f15\u53f7<\/p>\n\n\n\n<p>\u590d\u5236\u65f6\u591a\u4e86\u7a7a\u683c\/\u6362\u884c<\/p>\n\n\n\n<p>\u6570\u636e\u5e93\u7528\u6237\u548c\u6570\u636e\u5e93\u540d\u641e\u6df7<\/p>\n\n\n\n<p>\u7528\u4e86root\u8d26\u53f7\u4f46\u6ca1\u6743\u9650<\/p>\n\n\n\n<p>\u6570\u636e\u5e93\u670d\u52a1\u6ca1\u542f\u52a8<\/p>\n\n\n\n<p>90%\u7684\u60c5\u51b5\uff1awp-config.php\u6570\u636e\u5e93\u914d\u7f6e\u5199\u9519<\/p>\n\n\n\n<p>8%\u7684\u60c5\u51b5\uff1a\u6570\u636e\u5e93\u670d\u52a1\u672a\u542f\u52a8<\/p>\n\n\n\n<p>2%\u7684\u60c5\u51b5\uff1a\u6570\u636e\u5e93\u635f\u574f\/\u4e3b\u673a\u5546\u95ee\u9898<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>wordpress\u7f51\u7ad9\u8bbf\u95ee\u65f6\u51fa\u73b0\u201cError establishing a database connection\u201d\u7684\u539f\u56e0\u548c\u89e3\u51b3\u65b9\u6cd5<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[111],"tags":[75,80,79],"class_list":["post-6722","post","type-post","status-publish","format-standard","hentry","category-jianzhan","tag-database","tag-mysql","tag-79"],"_links":{"self":[{"href":"https:\/\/topfreetheme.com\/index.php?rest_route=\/wp\/v2\/posts\/6722","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/topfreetheme.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/topfreetheme.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/topfreetheme.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/topfreetheme.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6722"}],"version-history":[{"count":2,"href":"https:\/\/topfreetheme.com\/index.php?rest_route=\/wp\/v2\/posts\/6722\/revisions"}],"predecessor-version":[{"id":6725,"href":"https:\/\/topfreetheme.com\/index.php?rest_route=\/wp\/v2\/posts\/6722\/revisions\/6725"}],"wp:attachment":[{"href":"https:\/\/topfreetheme.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/topfreetheme.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/topfreetheme.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}