家の鍵を忘れてしまい、外に出られなくなったことはありませんか?WordPressサイトからロックアウトされると、そんな気分になることがあります。特にハッカーに管理者アカウントを削除された場合は、とてもイライラします。でもご心配なく。
あなたのサイトを秘密の裏口のある家のように考えてみてください。その裏口とはサイトのデータベースで、通常はMySQLコードを使用してアクセスします。MySQLコードというと複雑に聞こえるかもしれませんが、裏側でサイトに変更を加えるための指示書のようなものです。
この投稿では、MySQLを使用して、あなたのサイトに新しい管理者アカウントを作成する方法を紹介する。これで、ハッカーを締め出し、コントロールを取り戻すことができます。
なぜMySQL経由でWordPressデータベースに管理ユーザーを追加するのか?
あるユーザーのサイトがハッキングされ、そのユーザーの管理者アカウントがデータベースから削除されるという問題に遭遇したことがあります。これにより、WordPressサイトからロックアウトされました。
私たちは、WordPressサイトに直接新しい管理ユーザーを作成することで、彼らのウェブサイトにアクセスできるようにすることができました。これは、ウェブブラウザを使ってMySQLデータベースを管理できるウェブベースのツール、phpMyAdminを使って行いました。
ハッカーや単にパスワードを忘れてしまったためにWordPressの管理エリアからロックアウトされてしまった場合。
ただし、MySQLの編集を行う前に、必ずデータベースのバックアップを取る必要があります。その後、サイトにログインできるようになったら、ハッキングされた WordPress サイトを修正するための初心者ガイドに従ってください。
ということで、MySQLを使ってWordPressのデータベースに管理ユーザーを追加する方法を見てみよう。
phpMyAdminでWordPressデータベースに管理ユーザーを追加する
phpMyAdminは、ほとんどのトップWordPressホスティングサービス会社にプリインストールされています。ホスティングアカウントのcPanelダッシュボードのデータベースセクションで見つけることができます。
Bluehostのコントロールパネルのスクリーンショットです:
アイコンをクリックすると、phpMyAdminインターフェースが開きます。左のカラムからWordPressデータベースを選択する必要があります。
その後、phpMyAdminはWordPressデータベースのすべてのテーブルを表示します。wp_users
テーブルとwp_usermeta
テーブルに変更を加えることになります。
wp_usersテーブルへのユーザーの追加
まず、wp_users
テーブルを見つけてクリックする。これにより、現在テーブルにリストされているユーザーが表示されます。
下のスクリーンショットで、デモサイトのテーブルにはユーザーIDが1と2の2つあることに注目してください。デモサイトに新規ユーザーを作成する場合、このIDは一意である必要があるので、数字の3を入力します。
画面上部の’Insert’タブをクリックし、新規管理ユーザーの情報を挿入する必要があります。
インサーターフォームのフィールドに以下の情報を追加する:
ID
:ユニークな番号を選ぶ(この例では3を使う)user_login
: ログイン時に使用するユーザー名。user_pass
:パスワードを追加し、機能メニューでMD5を選択してください(以下のスクリーンショットを参照)。user_nicename
: ユーザーのフルネームまたはニックネームuser_email
: ユーザーのメール・アドレスuser_url
: あなたのサイトのアドレスuser_registered
: カレンダーでユーザーが登録された日時を選択user_activation_key
: 空白のままuser_status
: 0に設定する。display_name
: ユーザーのフルネームまたは表示名
完了したら、必ず「Go」ボタンをクリックして新規ユーザーを保存してください。
wp_usermetaテーブルにユーザーを追加する
ここで、wp_usermeta
テーブルを見つけてクリックする必要がある。その後、前のステップと同じように「挿入」タブをクリックしてください。
次に、以下の情報をインサーターフォームに追加する必要がある:
unmeta_id
: 空白のまま(自動生成されます)user_id
: 前のステップで使用したユーザーIDmeta_key
: これはwp_capabilities
でなければならない。meta_value
: insert this:a:1:{s:13: "administrator";s:1: "1";}
.
その後、下にスクロールすると、2行目のフィールドが見つかるはずです。以下の情報を追加する必要がある:
unmeta_id
: 空白のまま(自動生成されます)user_id
: 前のステップで使用したユーザーIDmeta_key
:wp_user_levelを
入力する必要があります。メタ値
: 10
フィールドに情報を入力し終えたら、「Go」ボタンをクリックしてください。おめでとうございます、これで新しい管理者ユーザー名が作成されました!
これで、このユーザーに指定したユーザー名とパスワードを使ってWordPress管理エリアにログインできるはずです。
ログインしたらすぐに、ユーザー ” すべてのユーザーに移動し、作成したばかりのユーザー名をクリックする必要があります。
ここで、何も変更せずにページを一番下までスクロールし、「保存」ボタンをクリックする。
これにより、WordPressは作成したユーザーをクリーンアップし、必要な追加情報を追加します。
SQLクエリーを使ったWordPressデータベースへの管理ユーザー追加
もしあなたが開発者なら、コードを使ってプロセスをスピードアップすることができる。
このSQLクエリーをデータベースにドロップするだけです:
INSERT INTO `databasename`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('3', 'demo', MD5('demo'), 'Your Name', 'test@example.com', 'http://www.example.com/', '2022-09-01 00:00:00', '', '0', 'Your Name');
INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '3', 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '3', 'wp_user_level', '10');
databasename’を使用するデータベースに変更することを本当に〜してもよいですか?
また、最初の方法で説明したように、他の値を新規ユーザーに必要な値に変更することも忘れないでください。
WordPressの管理画面からロックアウトされたときの対処法に関するエキスパートガイド
MySQL経由で管理ユーザーを追加する方法がわかったところで、WordPressの管理エリアからロックアウトされたサイトを修正する方法についての投稿をご覧いただきたい。
- WordPress管理画面(wp-admin)からロックアウトされたときの対処法
- WordPressリカバリーモードの使い方
- phpMyAdminからWordPressのパスワードをリセットする方法
- WordPressのログイン試行回数制限を解除する方法
- WP-Adminにアクセスできないときにすべてのプラグインを無効化する方法
- WordPressの死の白い画面を修正する方法(ステップバイステップ)
- WordPressの重大なエラーを修正する方法(ステップバイステップ)
- WordPressログインページのリフレッシュとリダイレクトの問題を解決する方法
- WordPressのデータベース接続確立エラーを修正する方法
- WordPressの「このサイトにアクセスできません」エラーを簡単に修正する方法
このチュートリアルで、MySQL を使って 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.
Syed Balkhi
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!
Mark C
WARNING! If your WordPress database has a custom table prefix rather than wp_ you’ll need to use that for the capabilities and user_level entries or you’ll get issues trying to access the dashboard.
For example, if your database table prefix is wp_abcdef_ then you would use wp_abcdef_capabilities and wp_abcdef_user_level in the appropriate fields when inserting the usermeta table record.
Also, it is easy to get confused in phpmyadmin, think you didn’t press the Go button, and click the Go button again when adding a record.
WPBeginner Support
Thank you for clarifying that should anyone run into an issue!
管理者
Dennis Muthomi
this is super helpful for those times when you’re locked out of your site. I do have a quick question
I recently hired a freelance developer to work on a custom plugin for my site, but she needs admin access to get the job done.
the thing is, I’ve never given anyone else admin privileges before, and I’m a bit hesitant to hand over the admin rights,.Is there a way to create a temporary admin account or limit the time she has admin rights? I want to make sure my site stays secure while still giving her the access she needs.Thanks
WPBeginner Support
For that we would recommend taking a look at our article below that covers some options available to you
https://www.wpbeginner.com/opinion/should-you-give-admin-access-to-plugin-developers-for-fixing-bugs/
管理者
An
This guide just made my life so much easier!
I don’t know you but I love you!
Thanks!
Max Johnson
The user is inserted. The site accepts the credentials
but
site does not allow use of admin panel: /wp-admin
“Sorry, you are not allowed to access this page.”
This is WordPress 6.4.2 & PHP 8.2
WPBeginner Support
That looks like a message from a security plugin or security setting from your hosting provider. You can try disabling any plugins following our guide below but if that does not work you would want to reach out to your host and they should be able to assist!
https://www.wpbeginner.com/plugins/how-to-deactivate-all-plugins-when-not-able-to-access-wp-admin/
管理者
Navin Rangar
It’s not working for me, sadly. I’ve checked and everything is showing in the database tables, but the website says the email address is not registered. If I try username it says it’s not recognised. Any ideas would be gratefully received!
WPBeginner Support
You may want to check that you do not have multiple databases in the chance that a placeholder site was set up when you first signed up with your hosting provider.
管理者
Kashif Ali
I want Create Editor user in database ?
WPBeginner Support
For editor users, we would recommend manually creating them through the WordPress interface using an admin account.
管理者
perceval hasselman
I am so happy for your explanation. This saves me a lot of work.
It was hard to do without knowledge but this tutorial did it for me
Thanks a lot!
WPBeginner Support
Happy to hear our guide was helpful!
管理者
Eleanor
It’s not working for me, sadly. I’ve checked and everything is showing in the database tables, but the website says the email address is not registered. If I try username it says it’s not recognised. Any ideas would be gratefully received!
WPBeginner Support
It is hard to say the specific reason but for an alternate method we would recommend trying the method from our guide below!
https://www.wpbeginner.com/wp-tutorials/how-to-add-an-admin-user-in-wordpress-using-ftp/
管理者
Lucas
Thank you a lot. You save my life, bro. thks
WPBeginner Support
Glad our guide was helpful!
管理者
newbie
Hi there,
I’m trying to move my live wordpress site to my local server because I need to do an updates.
However after setting up in the local server I’m not able to login and I came accross this article
‘Adding an Admin User to the WordPress Database Using a SQL Query’. My questions is the adding of this user should be done in the live server or my local server.
Thank you.
WPBeginner Support
Instead of creating a new user on your localhost installation, we would first recommend going through our guide below:
https://www.wpbeginner.com/wp-tutorials/how-to-reset-wordpress-admin-password-on-localhost/
管理者
Sam
Excellent article. Forgot login details after years of hiatus.
WPBeginner Support
Glad our article was able to help!
管理者
daniele
done but is not working for me. I created an account but wo see it as subscriber account not an admin.
WPBeginner Support
There is a chance there was a typo in the query depending on the method you’re using. For a workaround you may want to take a look at the alternative method in our article below:
https://www.wpbeginner.com/wp-tutorials/how-to-add-an-admin-user-in-wordpress-using-ftp/
管理者
Nibedita
Thanks for the tips it really worked and i could know a lot more about configuration i wordpress.
WPBeginner Support
Glad our article could help you learn
管理者
Farkas Tibor
Thanks, it saved me from a lot of work.
WPBeginner Support
Glad our guide was helpful!
管理者
MKallas
Thank you. This might come handy in other cases too… I made a Local AMPPS Wordpress Install and for some reason first registrant got Subscriber rights instead of Admin. Really interesting. Anyways, PhpMyAdmin and fix of wp_usermeta -> wp_usercapabilities -> “a:1:{s:13:”administrator”;s:1:”1″;}” sorted it out.
Andy
Hi, thanks for the info. I’ve only been able to login as a general ‘User’ using this method – I can’t see/access the Admin Dashboard. The site is a directory site that i migrated from a backup to a new domain. Any suggestions to get full admin privileges?
B A
I come here 2-3 times a year to get that nice set of SQL boilerplate. Should probably just save it to my notes at this point. Thanks so much!
WPBeginner Support
Glad our guide is able to continue to be helpful
管理者
Jana
Thank you so much for this post! I had so many problems after migrating and changing the base url of my site and this post solved them all.
WPBeginner Support
Glad our guide was able to help
管理者
Kristen
I followed these steps and see my new account, but my site still will not allow me to log in. It says invalid user, then if I try resetting the password it says no account exists. What’s my next step to fix this?
WPBeginner Support
You may want to ensure you added the user to the correct database, you should also be able to reach out to your hosting provider for them to take a look.
管理者
Kyle Eggleston
Excellent, useful tutorial. Thanks for publishing.
WPBeginner Support
You’re welcome
管理者
Stefan Pl
1. Please change the post to include information about table prefixes – a problem that appeared quite a few times in the comments and will keep you from succeeding if you just follow the post and have an alternative prefix.
2. Thanks for the information presented here
WPBeginner Support
Thank you for your feedback about our post
管理者
Mandy
For everyone who can login but not see the wp-admin, these instructions aren’t wholly correct.
The wp_cabailities meta_value actually needs to be set as a:1:{s:13:”administrator”;b:1;}
Otherwise your user doesn’t end up with a role set and you can’t see wp-admin.
WPBeginner Support
Thank you for sharing the code that worked for you
管理者
Jan
Yes this also worked me, Many Thanks!
Cristina
Hi. My Wordpress website is being managed by a remote developer. He is an admin and so am I. We have a monthly agreement and I have every intention of paying him his dues. What measures can I do to make sure that I keep the access as well as my website should things go sideways? Can you please help me? Thanks in advance.
WPBeginner Support
Create backups of your site and as long as you are the one paying for hosting you can restore the site
管理者
Janne
Hi,
Thanks for writing this! I see I am not the only one who was looking for instructions. My user was created, and I can click on the “Reset password” link and also get an e-mail from the system, but I am not able to log in. I saw that my “usermeta” table looks different from the other users’ – mine starts with “closedpostboxes_attachment”, not “first_name” etc. What might be the reason for that?
j
WPBeginner Support
That table is for meta boxes that you have closed, the order you’re seeing the table shouldn’t cause an issue
管理者
Sofia
Hi!
I did all the process but when I log in to the dashboard I only see the “Welcome to WordPress” section, I don’t see anything else in the admin area.
Please, can you help me?
WPBeginner Support
Your hosting provider may have customized their login area, there is normally an advanced section you can go to or reach out to your host and they should be able to assist
管理者
Alexander Mtembenuzeni
This was really helpful. Thank you!
WPBeginner Support
Glad our post was helpful
管理者
Anisha
Working on this for days. Thank you…
WPBeginner Support
Glad our article could help you
管理者
Glenn Gordon
I have a WP blog site which I have been locked out of. I created a new admin and can log in, but not to my dashboard. Instead, I go to my main blog page with my name and admin # at the top right and a logout button. How do I gain access to my admin/dashboard area?
WPBeginner Support
You should be able to add /wp-admin to the end of your domain to get to your admin area but if you have a plugin locking you out, you could disable it using: https://www.wpbeginner.com/plugins/how-to-deactivate-all-plugins-when-not-able-to-access-wp-admin/
管理者
Asif
Thank you very much!
WPBeginner Support
You’re welcome
管理者
João
Hello,
Well, this is embarrassing but… would anyone be able and kind enough to help me solve the father of problems? – wp_users table gone/missing…
Thank you in advance.
WPBeginner Support
You would want to reach out to your hosting provider if that table is not with your database to see if they have a backup of your database to restore.
管理者
lhoucine
hi! thank you for your tutorials,
i did all these steps and my issue still the same, when I want to login to my wp-admin, show me this message “Sorry, you are not allowed to access this page.” please if know how to fix this I will so thankful
thank you
WPBeginner Support
If the user was created, have you tried disabling your plugins in case you have a plugin that could be preventing access? https://www.wpbeginner.com/plugins/how-to-deactivate-all-plugins-when-not-able-to-access-wp-admin/
管理者
Theo
Make sure you replace wp_capabilities with the correct prefix, if you are using a custom one, for example asdf_capabilities
Emmanuel Ekanem
Thank you for this info, Theo.
wp_capabilities didn’t work for me cos mine is custom and it’s wpix_capabilities.
Thank you once again.
Holly Fitzgerald
After backing up my database with updraftPlus, then restoring it, we lost all admin access. I followed these instructions but am still getting an error saying I do not have access. Help!
WPBeginner Support
You would first want to reach out to updraftplus for your old login, some caching plugins can cause issues with what database your site is attempting to use. If that does not work you can force reset the password for your user using the method in our article here: https://www.wpbeginner.com/beginners-guide/how-to-reset-a-wordpress-password-from-phpmyadmin/
管理者
john juncal
you are an absolute legend! after3 hours of trying useless suggestion from forums, you came up trumps, thank you!
WPBeginner Support
Glad our article could help
管理者
stephane
You Save my Life. Thank you so much!
WPBeginner Support
Glad our article could be helpful
管理者
Gina
EXCELLENT tutorial. Thank you so much!
mahmud
many many thanks bro. you are genius.
Punam
Many Many thank.. it is very helpful to me and my site work perfectly…
Taieuro
Thanks your information!
But after inserting a admin accout, i can not login my site.
Appear “Protection” button stop me to login WP dashboard.
Please help me!
WPBeginner Support
Hi Taieuro,
Please try steps in our WordPress troubleshooting guide, it will help you figure out what’s causing the issue.
管理者
Matthew
Didn’t work, I’m getting the “Sorry, you are not allowed to access this page.” message. I checked my wp-config.php and the prefix is “wp_” but it still doesn’t work. Any ideas?
Cavid Muradov
You helped my life, thank you very much.
Julia
Thank you so much. Worked perfectly. You helped me so much!
Julia
Rivhie
How did you do it? It didn’t work for me.
Chakerz
Hi,
change “wp_” to your installation prefix !!
UgoChukwu Agbams
Thank you very much. This article really helped me a lot, after my admin account was set to customer by a plugin I set to change user role from whatever to customer when they made a purchase.
I never knew it will affect the admin role as well.
JOEL
Very good, great info. The SQL worked super fast so thumbs up!
kerry
is there a common reason why user can login but Dashboard is not made available? I see a lot of meta key values in the db
Jules
Thank you, this has been very helpful.
PM
Thank you sooooo much for this. Just this morning my wordpress site was hacked and I could not login into wp-admin. It was giving “user not found” error. I used this to fix things in my hostgator account.
Very very grateful. Written instructions are excellent but the video could be slower with more details.
joel
Hi all,
it didn’t work for me…
an error message tell me that I can’t access to the dashboard
!!HELP !!
Anup Poudel
It is simple mate.See what is written in you database name.
Like in my case it was wprn_capabilities,wprn_user_level..
James Denning
I have the same problem. No matter what I do the user does not have any privliges
Shaheen
I messed around with this more; watched the video several times and it’s still not working.
In my case, I lost admin access after I migrated my WP site from one hosting account to another.
my old admin login is able to login but once in, isn’t able to do anything.
Using mysql, i tried creating a new user and adding the meta data. When I try to login with the new user, it says the password is incorrect. I tried saying “forgot password” and I did not receive any email to the email address i included when making the user with msql.
In mysql i can see my old admin user is still there. I tried adding meta data to give admin privledges to that user, by putting in the corresponding userID. This didn’t change anything. I am still able to login with that user but don’t have access to anything. If anyone has any advice it would be much appreciated!