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

LocalhostでWordPressの管理者パスワードをリセットする方法

ローカルのWordPressサイトからロックアウトされると、作業が止まってしまうことがあります。テーマをテストしているときや、クライアントプロジェクトをローカル環境でセットアップしているときに、このようなことが起こったことがあります。

もどかしいのは、パスワードリセットのメールがローカルホストのセットアップでは機能しないことだ。だから、”Lost your password? “をクリックしても、受信トレイには何も表示されない。

ありがたいことに、メールにアクセスしなくてもWordPressの管理者パスワードをリセットする簡単な方法がある。私たちは、これらの方法を数え切れないほど使って、ローカルサイトに戻りました。

このチュートリアルでは、phpMyAdminまたはWP-CLIを使用して、ローカルホストのWordPress管理者パスワードをリセットする方法を紹介します。

Resetting the admin password in WordPress on localhost

Localhostでパスワードのリセットがうまくいかない理由

ローカルホスト」とは、ローカルサーバー(通常はあなたのコンピューター)のことです。本番稼動前にWordPressサイトを構築し、テストすることができるプライベートスペースです。

新しいプラグインやデザインの変更を試したり、WordPressの仕組みを学んだりするためにローカルホストを使うことがよくあります。心配することなく物事を壊すことができる安全な方法です。

まだ試したことのない方は、これらのガイドを参考にしてください:

さて、ここからが初心者が混乱しやすい部分だ。ローカルサイトの管理者パスワードを忘れた場合、通常の「パスワードをお忘れですか?

WordPressは通常、パスワードリセットのメールを送信しますが、ローカルホストのセットアップでは、手動で設定しない限りメールを送信できないからです。初期設定では、ほとんどの人が設定していません。

幸運なことに、パスワードの再設定にメールは必要ありません。完全にロックアウトされている場合でも、localhostでパスワードをリセットする2つの簡単な方法を紹介します。

方法1:phpMyAdminを使用してローカルホストのWordPress管理者パスワードをリセットする

XAMPP、WAMP、MAMPなどのツールを使っているなら、phpMyAdminはすでにインストールされているはずです。私たちは、パスワードのリセットなど、データベースを直接調整するために何度も使用してきました。

phpMyAdminは、WordPressデータベースを管理するためのビジュアルなインターフェースを提供します。複雑そうに聞こえますが、コツをつかめばとても簡単です。

注: LocalWPを使用している場合、代わりにAdminerというツールが表示されます。このツールはphpMyAdminと同じように動作するので、これらの手順を簡単に実行することができます。

Adminer the phyMyAdmin alternative in LocalWP

まず、ブラウザーでこのアドレスにアクセスしてください:

http://localhost/phpmyadmin/

ログインを求められるかもしれません。ほとんどのセットアップでは、ユーザー名はrootで、パスワードフィールドは空のままです。

phpMyAdminに入ったら、サイドバーでWordPressデータベース名を探してクリックします。

Open your database in phpMyAdmin

データベース内のテーブルのリストが表示されます。usersで終わるテーブルを探し、その横のBrowseリンクをクリックします。

注:ほとんどのWordPressサイトはプレフィックスとしてwp_を使用していますが、セットアップ中に変更した場合は異なる可能性があります。

Open users table in WordPress database

サイトのユーザー一覧が表示されます。管理者ユーザー名の行を探し、その横にある編集リンクをクリックしてください。

Edit user in WordPress database

データベースに保存されているすべてのユーザー・データを表示するフォームが開きます。user_passフィールドが見つかるまで下にスクロールしてください。

: カラムに新しいパスワードを入力します。次に「Function」列で、ドロップダウンから「MD5」を選択します。

Add new user password

WordPressはパスワードを暗号化して保存するが、MD5はそのフォーマットを認識するのに役立つ。

一番下のGoボタンをクリックして変更を保存します。

Save database changes

これで完了です!これで、設定した新しいパスワードを使ってローカルのWordPressサイトにログインできます。

方法2:Functions.phpファイルでパスワードをリセットする

phpMyAdminにアクセスできない場合や、別の方法をご希望の場合は、テーマのfunctions.phpファイルを編集することで、WordPress管理者パスワードをリセットすることができます。この方法は簡単で、すぐに実行できます。

ステップ1:テーマのFunctions.phpファイルにアクセスする

まず、有効化したテーマのfunctions.phpファイルを見つける必要があります。これを行うには、ローカルホスト上のWordPressインストールのルートディレクトリに移動します。

使用しているソフトウェアによって、ルート・ディレクトリの場所が異なる場合があります。例えば、Localを使用している場合、サイトは以下の場所に置かれます:

C:◆Usersersyourusername ◆Local Sites ◆yoursitename

次に、/wp-content/themes/フォルダーに移動します。その中に、有効化したテーマと同じ名前のフォルダーがあります。

Locating your theme folder

有効化したテーマのフォルダー内で、functions.phpという名前のファイルを探し、メモ帳やテキストエディットのようなテキストエディターで開きます。

ステップ2:パスワードをリセットするコードを追加する

functions.phpファイルの一番下に、以下のコードを貼り付けます:

1
2
3
4
5
6
function reset_admin_password() {
    $user_id = 1; // ID of the admin user
    $new_password = 'newpassword123'; // Your new password
    wp_set_password($new_password, $user_id);
}
add_action('init', 'reset_admin_password');

newpassword123」を、使用したいより強力なパスワードに置き換えることをお忘れなく。

このコードでは、IDが1のadminユーザーに新しいパスワードを設定しています。しかし、ユーザーIDはわからないがadminのメールは知っているという場合は、代わりにこのコード・スニペットを使うことができます:

1
2
3
4
5
6
7
8
9
function reset_admin_password_by_email() {
    $user_email = 'admin@example.com'; // Admin user's email address
    $user = get_user_by('email', $user_email);
    if ($user) {
        $new_password = 'newpassword123'; // Your new password
        wp_set_password($new_password, $user->ID);
    }
}
add_action('init', 'reset_admin_password_by_email');

このコードでは、指定されたメール・アドレスに関連付けられたadminユーザーに新しいパスワード(newpassword123)を設定します。

コードを追加したら、functions.phpファイルを保存し、ブラウザーでローカルホストのWordPressサイトを更新します。これで、新しいパスワードを使ってログインできるはずです。

ステップ4:コードの削除

ログインに成功したら、潜在的なセキュリティリスクを避けるために、functions.phpファイルからコードスニペットを削除することが重要です。

functions.phpファイルを開き、先ほど追加したコードを削除するだけです。変更を保存するのを忘れないでください。

ボーナス・リソース

WordPressのパスワードと管理者アカウントの管理に関するヒントとチュートリアルを以下に追加します:

この投稿が、ローカルサーバー上のWordPress管理者パスワードのリセットのお役に立てば幸いです。WordPressの一時ログインを作成するチュートリアルや、WordPressにワンクリックでGoogleログインを追加する方法をご覧ください。

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.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

アバター

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.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

63件のコメントLeave a Reply

  1. Hafiz Muhammad Ansar

    Very nice blog for WordPress help. I recommend for beginners to use this platform. Thankful!

    • WPBeginner Support

      Glad you found our article helpful!

      Admin

  2. Abdullah

    Amazing, it worked

    • WPBeginner Support

      Glad our guide was helpful!

      Admin

  3. Nidhi Gupta

    it’s really helpful, thankyou so much

    • WPBeginner Support

      Glad our guide was helpful!

      Admin

  4. Habu

    Omg you save my life !!! THANK YOU VERY MUCHH !!!

  5. Jahir

    I can not log in now same process…any updates?

    • WPBeginner Support

      The most common issue would be if you did not set the function to MD5 or click go to apply the changes, you would want to ensure you have done that correctly.

      Admin

  6. Kamondo

    Wonderful! problem solved. Very Simple steps but powerful.

    • WPBeginner Support

      Glad our guide was helpful :)

      Admin

  7. Joe

    I’m encoutering this problem now after installing the 2nd WordPress on MAMP. This article is very to the point and I’ll try it tomorrow!

    • WPBeginner Support

      We hope the guide helps :)

      Admin

  8. Gerron

    Solid solid info right here, thanks a lot, really helped, so simple

    • WPBeginner Support

      Glad our guide was helpful :)

      Admin

  9. Odineks

    Thank you so much. I always find solutions to every of my WP problems here.
    I kept having problems with the login page on the frontend not recognizing my new password, I didn’t realize there is a function to pass that message to myPHPadmin.

    • WPBeginner Support

      Glad our guide was helpful :)

      Admin

  10. naved ahmed

    Thanks a lot. Finally problem solved within a minute.

    • WPBeginner Support

      Glad our guide was helpful :)

      Admin

  11. Mohsin

    I just love this
    Love the way you write every thing

    • WPBeginner Support

      Thank you, glad you like our content :)

      Admin

  12. Jen

    I tried this and while I was in there also attempted to change my username, which I realize was probably my mistake… but now I can’t log in at all. Is there a way to undo what I’ve done?

    • WPBeginner Support

      You would need to follow the steps in the article and that would bring you back to where you could edit, you should also be able to use your email as an alternative

      Admin

  13. Justina

    Your Blog is always so full of rich articles. Thanks so much. was stuck for a while because I skip the MD5 option. You are a lifesaver.

    • WPBeginner Support

      Glad our guide could be helpful :)

      Admin

  14. Sarah

    Thank you SO MUCH for this! You saved me so many more hours of tinkering with trying to figure out how to log in!!

    • WPBeginner Support

      Glad we were able to help :)

      Admin

  15. David

    Thank you ever so much! Normally, I keep this stuff handy; but in this case, I did could not find where I wrote the information down.

    You saved a total re-work of a site I was planning.

    • WPBeginner Support

      Glad our guide could be helpful :)

      Admin

  16. adeel kamran

    You saved me, I had a lot of work there.

    • WPBeginner Support

      Glad our guide could help :)

      Admin

  17. lokesh n

    thank you it’s really working thank you

    • WPBeginner Support

      You’re welcome glad our article was helpful :)

      Admin

  18. Vivek

    Hi,
    When I reset My password through link then what fileds affected in Database and in which table.

    Kindly share this information i am waiting for your response.

  19. Adnan Khan

    After half an hour of search i just found my help from this site, which solves my problem in no time,
    thanks a lot
    keep it up guys

    • WPBeginner Support

      You’re welcome, glad our guides can be helpful :)

      Admin

  20. Tenasu Mensah

    thanks a lot, kudos to you guys keep the good work doing,you guys are doing great job

    • WPBeginner Support

      Glad our guide could help :)

      Admin

  21. Anuj

    It work fine, Thanku so much,

  22. Pádraig

    Really simple and great explanation.

    Many thanks for sharing.

  23. Saranya

    Works Good! Thanks a lot.

  24. Patr

    Hello,
    I type a new password , click continue and it does not keep the password, it shows a long string of numbers and letters. If I use this , still cannot log in. It looks simple on the video but does not work for me. Thank you.
    I looked everywhere on the internet, no solution worling.

    • Jason

      Same problem here. Did you find a solution? Is there any chance of being hacked?

  25. Christian Gochez

    when I click on the Go button this error appears:

    #1881 – Operation not allowed when innodb_forced_recovery > 0

  26. Edward

    Simple and neat! worked thanks

  27. Handel

    I started to just reinstall wordpress, but then decided to do a google search, and there was GOOD OLD RELIABLE WpBeginner.com

    Thanks a million!!

  28. Sheriff

    very effective… kudos

  29. Icholia

    Hello

    THANKS, Wow there is no other place that you can get well explained information like this , i have been suffering but now i just followed your tutorial and it is a game changer i love you guys and i will always learn from you guys once again thanks

  30. CJ

    Thank you! For those who can’t make it work, remember to use the “MD5” function when changing the password. I almost skipped that part and was stuck for a few minutes.

  31. mohamad hossein

    so use full thank you so much

  32. Janet

    I got completely lost on the video so I tried plugging in the URL. Doesn’t work. Still lost.

  33. Ma

    Thanks so much, you saved me from what could have been a very embarrassing situation!

  34. James

    I change the password, username, userlogin and nickname not I cant login. Any advice?

    • suganya

      i can’t able to login .because it’s shows me like email is not registered .so what can i do???

  35. Jac

    Thanks so much for providing this info – I was really stuck!

  36. Gerhard SCHNEIBEL

    Thanks a lot for your help. I am very happy with “wpbeginners”.

  37. Renu

    it worked.. thanks a ton..

  38. Anthony

    Hi…
    I am so thankful for such great information you provide. I have bookmarked your site a while back.
    I have been working on a site in wordpress using xampp on the Apache local server. Just recently, I am not able to login on the admin page. I have managed to create a user name and password that works on about 95% of all sites requiring me to register. I also created a file that lists all my login info for everywhere I need to login, including the WP admin login page, IF I ever forget that info.
    I have read this page (https://www.wpbeginner.com/wp-tutorials/how-to-reset-wordpress-admin-password-on-localhost/) and watched the video, also. The only problem is that when I click on the wp_users in phpMyadmin, I get this error- ‘#1932 – Table ‘bitnami_wordpress.wp_users’ doesn’t exist in engine.’
    Am I reduced to re-installing WordPress, or is there another way around it?
    I have tried restoring my computer (using system restore) to various past restore points, but with no luck. Can you help me with this?
    I would be so thankful!!! I have put months of work into designing a site to launch, and I HAVE exported everything to a file quite a few times using WordPress import plugin (something like that).

    Could you provide a solution?

    Thank you so much…

    Anthony

  39. Kakaire Charles

    Extremely wonderful. Thank you for sharing.

  40. Gaurav

    i tried this but not working

  41. shaikh muneer

    super way to reset admin password thank you for share this

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.