Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPBカップ
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

WordPressでデータベース接続の確立エラーを修正する方法

編集メモ: WPBeginner のパートナーリンクから手数料を得ています。手数料は編集者の意見や評価に影響を与えません。編集プロセスについて詳しく知る。

WordPressで「Error establishing a database connection(データベース接続の確立エラー)」通知が表示されていませんか?

サイトにユーザーがアクセスできなくなる致命的なエラーです。WordPressがデータベースに接続できない場合に発生します。複数の要因がこの接続に影響する可能性があるため、初心者がこのエラーをトラブルシューティングするのは少し難しいかもしれません。

この投稿では、WordPressサイトの「Error establishing a database connection(データベース接続の確立エラー)」を簡単に修正する方法を順を追って説明します。

Fix the Error Establishing a Database Connection in WordPress

WordPressのデータベース接続確立エラーの原因は?

データベースとは、データを簡単に保存、整理し、他のソフトウェアから取り出すためのソフトウェアである。

コンテンツ管理システムであるWordPressは、すべてのコンテンツやその他のサイトデータを保存するためにデータベースを使用します。そして、誰かがあなたのサイトにアクセスするたびにデータベースに接続します。

WordPressはデータベースに接続するために以下の情報が必要です:

  • データベース名
  • データベースのユーザー名とパスワード
  • データベースサーバー

この情報は、wp-config.phpと呼ばれるWordPressの設定ファイルに保存されます。

これらの情報に誤りがある場合、WordPressはデータベースサーバーへの接続に失敗し、「Error establishing a database connection(データベース接続の確立エラー)」というエラーが表示されます。

Database connection error in WordPress

WordPressで最もよく見られるエラーのひとつです。不正なログイン情報以外にも、データベースサーバーがダウンしていたり、データベースファイルが破損している場合にもこのエラーが表示されることがあります。

それでは、WordPressの「Error establishing database connection(データベース接続の確立エラー)」問題を解決する方法を、ステップ・バイ・ステップのトラブルシューティングとともに見ていきましょう。

1.WordPressデータベースのログイン情報を確認する

データベース接続エラーの最も一般的な原因は、ログイン情報が正しくないことです。WordPressサイトを最近新しいホスティングサービスに移行した場合は、この問題が考えられます。

WordPressデータベースのログイン情報は、wp-config.phpファイルに保存されています。これはWordPressの設定ファイルで、データベース情報を含む重要な設定が含まれています。

wp-config.phpファイルを編集したことがない場合は、初心者向けのwp-config.phpファイルの編集方法をご覧ください。

wp-config.phpファイルで以下の行を探します:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );
/** MySQL database username */
define( 'DB_USER', 'username_here' );
/** MySQL database password */
define( 'DB_PASSWORD', 'password_here' );
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

ここで、データベース名、ユーザー名、パスワード、データベースホストの情報が正しいことを確認しなければなりません。

この情報は、WordPressホスティングアカウントのダッシュボードから確認できます。このチュートリアルでは、Bluehost を使用しますが、他のホスティング パネルでも同様のプロセスになります。

ログイン中、左カラムの「ウェブサイト」タブをクリックし、「詳細設定」タブに切り替えます。次に、「データベース」セクションまでスクロールダウンし、その横にある「管理」ボタンをクリックします。

Click the Manage button next to the Database section

これにより、cPanelのMySQL Databasesページが新しいウィンドウで開きます。

ここで、’Current Database’ セクションにデータベース名とユーザー名があります。これらの情報をコピー&ペーストして、wp-configファイルに追加してください。

Find your database name and username in the Current Databases section

次に、「現在のユーザー」セクションまでスクロールダウンし、データベース名の横にある「パスワードの変更」リンクをクリックします。

新しい画面が表示され、データベースのパスワードを変更することができます。

Change your database password

データベースの詳細をすべて確認したら、必要に応じてwp-config.phpファイルで情報を変更できます。

その後、もう一度サイトにアクセスしてみて、データベース接続エラーがなくなっているかどうかを確認してください。

それでもエラーが表示される場合は、何か他の問題があることを意味します。

2.データベースホスティングサービス情報の確認

データベース名、ユーザー名、パスワードの情報が正確であることを確信している場合は、正しいデータベースホスティング情報を使用していることを確認してください。

ほとんどのWordPressホスティング会社は、データベースのホスティングサービスとしてlocalhostを使用しています。しかし、一部のマネージドWordPressホスティング会社は、データベースのホスティングサービスに区切りのサーバーを使用しています。その場合、データベースのホスティングサービスはlocalhostではありません。

つまり、WordPressホスティングサービス会社に連絡して、これらの詳細を確認する必要があります。

3.WordPressデータベースの修復

現在、wp-adminダッシュボードで「1つまたは複数のデータベーステーブルが使用できません」または「データベースの修復が必要な場合があります」のような別のエラーが表示されている可能性があります。その場合は、データベースを修復する必要があります。

これは、wp-config.phpファイルに以下の行を追加することで可能です。本当に〜してもよいですか?Happy blogging’の行の直前に追加してください:

define('WP_ALLOW_REPAIR', true);

設定が完了したら、このページhttp://www.yoursite.com/wp-admin/maint/repair.php。yoursite.comを自分のドメイン名に置き換えてください。

ここで、「データベースの修復」ボタンをクリックしてプロセスを開始する必要があります。

Repair WordPress database

注:データベース修復ページにアクセスするために、ユーザーはログイン中である必要はありません。データベースの修復と最適化が完了したら、wp-config.phpからこの行を削除してください。

しかし、サイトにコードを追加したくない場合は、ホスティングアカウントのcPanelからデータベースを修復することもできます。

ホスティングサービスアカウントにアクセスし、左の列から「ウェブサイト」ページを開きます。次に、’Advanced’タブに切り替え、データベースセクションの’Manage’ボタンをクリックします。

Click the Manage button next to the Database section

新しいタブでcPanelが開きます。ここで、「データベースの修正」セクションまでスクロールダウンし、「データベースの修復」ドロップダウンメニューからデータベース名を選択します。

そうしたら、「データベースの修復」ボタンをクリックしてプロセスを開始する。

Click the Repair database button

ホスティングサービスパネルが自動的にデータベースを修復します。

プロセスが完了すると、成功のメッセージも表示されます。

Database repair success message

これでWordPressサイトにアクセスして、エラーが解決したかどうかを確認することができます。

4.データベースサーバーがダウンしていないか確認する

すべてが正しいように見えてもWordPressがデータベースに接続できない場合は、データベースサーバー(MySQLサーバー)がダウンしている可能性があります。

これは、サーバーのトラフィックが多いために起こる可能性があります。ホスティングサービスのサーバーが負荷に耐えられないのです(特に共有ホスティングの場合)。

このため、サイトが遅くなり、ユーザーによってはエラーが出力されることもあります。この場合、ホスティングサービスプロバイダーと電話またはライブチャットで、MySQLサーバーがレスポンシブかどうかを確認する必要があります。

さらに、同じサーバーで他のサイトを運営している場合は、それらのサイトをチェックして、SQLサーバーがダウンしていることを確認することができる。

同じホスティングアカウントに他のサイトがない場合は、ダッシュボードに移動し、[詳細設定]タブに切り替えるだけです。

その後、phpMyAdminセクションの横にある「管理」ボタンをクリックします。

Click the Manage button next to the PHPMyAdmin option

新しいウィンドウでphpMyAdminが開きますので、一番上の「データベース」設定をクリックしてください。

その後、データベースの名前をクリックして、その設定にアクセスしてください。それができたら、データベース・ユーザーに十分な権限があるかどうかをチェックしましょう。

Connect PHPMyAdmin with your database

そのためには、testconnection.phpというファイルを新規作成し、以下のコードを貼り付ける必要があります:

<?php
$link = mysqli_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully';
mysqli_close($link);
?>

コードを貼り付けたら、ユーザー名とパスワードを自分のものに置き換えてください。このファイルをサイトにアップロードし、ウェブブラウザーからアクセスすることができます。

スクリプトが正常に接続された場合は、ユーザーに十分な権限があることを意味します。

次に、wp-configファイルに戻り、すべての詳細が正確で、タイプミスがないことを確認するためにスキャンする必要があります。

ユーザーにとって効果的だったその他のソリューション

上記のトラブルシューティングのヒントでサイト上のデータベース接続エラーを修正できない場合は、以下の追加手順をお試しください。

ユーザーからの報告によると、これらの手順でサイト上のデータベース接続エラーを解決したユーザーもいます。

1.WordPressサイトのURL更新

cPanelのphpMyAdminを使ってWordPressサイトのURLを更新してみてください。

ホスティングアカウントのダッシュボードからphpMyAdminにアクセスし、リストからWordPressデータベースを選択するだけです。

その後、上部のSQLメニューに切り替え、次のMySQLクエリーを入力する:

UPDATE wp_options SET option_value='YOUR_SITE_URL' WHERE option_name='siteurl'

このように見えるはずだ:

Change site URL

WordPressのテーブル接頭辞を変更している可能性があるので、自分のサイトURLをプロバイダーで指定し、wp_optionsを自分のテーブル名に変更することをお忘れなく。

2.Webサーバーの再起動

専用サーバー、ローカルサーバー、仮想専用サーバー(VPS)のユーザーは、サーバーの再起動を試すことができる。

これによりWebサーバーとデータベースサーバーが再起動され、エラーの原因となる一時的な不具合が修正される可能性があります。

3.助けを求める

他のすべてがうまくいかない場合は、ホスティングサービス会社に連絡する必要があるかもしれません。すべての優れたWordPressホスティングサービス会社は、トラブルシューティングを手伝い、正しい方向を示し、あるいは問題を解決してくれます。

WPBeginnerプロサービスのようなプラットフォームを使ってWordPress開発者を雇い、リーズナブルな料金でこの問題を解決することもできます。WPBeginner Pro Services には、WordPress の問題を解決するために信頼できる専門の開発者チームがあります。

WPBeginner Pro Services

さらに、サイトのメンテナンス、ハッキングされたサイトの修復、スピードの最適化、サイトの再構築、SEOの最適化にもご利用いただけます。

この投稿がWordPressの「Error establishing a database connection」問題の解決に役立てば幸いです。WordPressの問題を自分で解決するためのヒントについては、WordPressトラブルシューティングガイド、またはWordPressのフリーランサーや開発者のための最高のツールの専門家のピックアップも参照してください。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

情報開示 私たちのコンテンツは読者支援型です。これは、あなたが私たちのリンクの一部をクリックした場合、私たちはコミッションを得ることができることを意味します。 WPBeginnerの資金源 をご覧ください。3$編集プロセスをご覧ください。

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

究極のWordPressツールキット

ツールキットへの無料アクセス - すべてのプロフェッショナルが持つべきWordPress関連製品とリソースのコレクション!

Reader Interactions

663件のコメント返信を残す

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Hajjalah says

    I used to get this error more often when I was logged into my admin dashboard for a longer period but this article helped me solve the issue. I just updated the WordPress Site URL. Thanks for the useful guide.

  3. Dennis Muthomi says

    I actually encountered this database connection error just recently when working on a staged WordPress site before going live.
    I had just moved a WordPress site from local to a vps. The video tutorial at timestamp 2:53; helped me solve the error :-)

  4. Jiří Vaněk says

    May I ask what the problem is, if I migrate the database to a new one, edit wp-config.php for the new connection, but wordpress does not connect? In the end, I had to delete the old wp-config and create new ones from the installation package. The only thing I found out was that the key stored in wp-config is probably a problem. Am I encrypting somehow connected to the DB and does it have to be removed from the wp-config file during the migration?

    • WPBeginner Support says

      You would want to ensure you have a user on that new database with the correct information that you have in your wp-config for the most common cause for that issue.

      管理者

    • WPBeginner Support says

      The steps in this guide should still be able to assist you and we would recommend reaching out to the support for the demo you are importing and they can look into what could be the root of the problem you are running into.

      管理者

  5. Henrik R. says

    I need to change the password for the MySQL database for security reasons.
    Isn’t there a way to login to the WP dashboard and tell WP about the new password, instead of having to change the wp-config.php file?

  6. LN says

    First I would like to say thanks for this guide!
    I am having an issue “Error establishing a database connection“ I have checked the wp-config.php and all the database information is correct. I wanted to try step 4 in this guide but I don’t really understand how. I logged in to phpMyAdmin, but not sure what the next step is. Do you have a video for that? I am not a developer just a new WP beginner.

    • WPBeginner Support says

      You would want to go to your hosting provider’s dashboard or reach out to your hosting provider and they should be able to assist.

      管理者

  7. Daniel says

    I almost have given up after having one issue after the other, till i read this. I had this feeling that “this is it” this is the solution I have been looking for. tried it and it worked perfectly, thanks a lot.

  8. Hrutik vijay kumthekar says

    I’m getting this error when entered the URL of my site:

    There has been a critical error on your website.

  9. jennifer mulder says

    I am getting this error
    Warning: mysqli_real_connect(): (HY000/2002): Connection refused in /home/f5853789/public_html/wp-includes/wp-db.php on line 1635
    Connection refused

    what do I do

    • WPBeginner Support says

      That is a different error, you would want to reach out to your hosting provider for assistance with that specific error.

      管理者

  10. Tejas Misra says

    I am a beginner to WordPress, and I am using MAMP to install WordPress but I’m still getting this error. My credentials are correct, and none of the steps shown above appeared to work. The database is repaired too. I don’t know what to do.

  11. sain says

    Hi, I have just moved my WordPress site to a new hosting provider via ftp when this error popped up. Is there anything I’m to update after a migration? Thanks

  12. KWS Adams says

    Adding this line “””define(‘WP_ALLOW_REPAIR’, true);”” helped me get my site back after 14 hours of being down. Thought it was my hosts problem. Thanks for the info.

  13. Zubair Rahman says

    How to increase the connection limit in the MySQL database? My website is intermittently giving database error as it is exceeding the max connection limit allocated on the server.

    • WPBeginner Support says

      You would need to reach out to your hosting provider for changing that and they would be able to assist.

      管理者

  14. Nimra afridi says

    I have installed a wordpress . i also make post but sometime it shows me that ”please install wordpress”. Why it showing me that?
    Thank you.

    • WPBeginner Support says

      There are a few possible reasons, you may want to reach out to your hosting provider to ensure there are no hiccups on their end.

      管理者

  15. alex says

    my website is hosted on aws and i accessed the MYSQL folder via filezila but i couldn’t find the file that contains database username , password and hostname. is there any specific name of that file?

  16. Deborah N. says

    Thanks. Adding the repair code to my wp config file worked. I appreciate the article. It was straight forward and easy to follow.

  17. bloggeryanke says

    your article was helpful i had changed my database password so it wasnt connecting to my blog properly but all thanks to your article the issue has been fixed

  18. Joe Marzi says

    Thank you for sharing such a nice blog.
    It will help the beginners of WordPress who are facing the problem regarding Error Establishing in the database connection. Apart from that, It gives a step by step solution so, every reader can easily solve the problem.

  19. Irwin says

    I got this error after forcefully shutting my computer. After trying all these suggested methods and failing, I rebooted my computer and the database error was fixed.
    You should give it a try too if things go south.

  20. Nick Aninsley says

    Thank you so much for sharing this tutorial. Actually, had installed WordPress, it shows me “Error Establishing A Database Connection” and I don’t know what to do. Then I have searched on Google and I found your this article and really it is
    very helpful for me and also many people who have no idea about this things. and my site were facing many other problems and only one of them has been solved. Thank for article.

  21. Emily says

    I can’t back up my site or do any of what you suggest, because I cannot get into the administrative section of my blog. I can view it, as a viewer, but I have no access to anything more. I also cannot find anyway to contact people from wordpress! Help!?!!

  22. Waqas Gulzar says

    Guys,

    I have fixed it now for my website

    It was due to insufficient PHP memory
    I have updated my php.ini to increase the PHP memory

  23. ken says

    I’m on BlueHost and just upgraded to WP 5.2 and got the dreaded error message:

    “Your PHP installation appears to be missing the MySQL extension which is required by WordPress.”

    I tried with PHP 5.6, 7.0 & 7.1 – all give the same response. Any ideas what I can try? My site is completely blocked by the error.

  24. ravendra says

    hello I need your help please help me my website is showing Error establishing a database connection
    how can I solve I don’t know please help me

    • WPBeginner Support says

      You would want to follow the troubleshooting steps in this article for that error.

      管理者

  25. Daniel says

    I had this very same issue while using Xampp. After using the “testconection.php” file and through some further trouble shooting, I discovered that my user account was set to connect to “Any host” and by changing it to “Localhost” the problem was solved. I suspect this error came about when I updated Xampp and recreated the same named user.

    • Della says

      For my case the correct response was by Daniel.
      …I discovered that my user account was set to connect to “Any host” and by changing it to “Localhost” the problem was solved.

      Thanks so much!

    • WPBeginner Support says

      The methods in this article should be able to help with localhost sites as well as hosted sites.

      管理者

  26. Cosme Fulanito says

    After succeed the “Check your Web Host (MySQL Server)” test I change the host from 127.0.01 to localhost on the config.php file.

    That worked for me.

  27. Vinay Mourya says

    hi, it is happening to my WordPress site only sometimes and when I reload the page site starts working again please suggest me a solution, for now, I am using Cloudflare as cdn and wp rocket for caching plugin, the theme is newspaper premium.

    • WPBeginner Support says

      If it is intermittent like that, you would want to reach out to your hosting provider and let them know and they should be able to assist.

      管理者

  28. Gee says

    Same exact error i got “Error establishing a database connection” but not all of the sollution you mentíon helped me.

    For me the MySql services was disabled: I went to services and start the MySQL to automatic. The other thing was the ” log on ” to user was administrator and changed it to the account i created.

    Now my wordpress site is working again.

  29. Umar says

    I have a weird situation is, that the error establishing a database connection is only happening to one post in my blog while other posts are not showing this issue.

  30. rabda says

    I am receiving this error one time on 3 and not always! I do not understand why and how to solve the problem

    • WPBeginner Support says

      You may want to try reaching out to your hosting provider to see if their error logs have information that can help find the root of the issue.

      管理者

  31. Ryan says

    thanks so much, worked great, really appreciate how fast and to the point the video was, instead of a 7-10min extended one, boom, stright to the point!

返信を残す

コメントありがとうございます。すべてのコメントは私たちのコメントポリシーに従ってモデレートされ、あなたのメールアドレスが公開されることはありませんのでご留意ください。名前欄にキーワードを使用しないでください。個人的で有意義な会話をしましょう。