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

Så här lägger du till en admin-användare i WordPress Database via MySQL

Har du någonsin glömt din husnyckel och känt dig fast utomhus? Att bli utelåst från din WordPress-webbplats kan kännas ungefär så. Det är superfrustrerande, särskilt om hackare har raderat ditt administratörskonto. Men oroa dig inte, du kan komma tillbaka in.

Tänk på din webbplats som ett hus med en hemlig bakdörr. Bakdörren är webbplatsens databas, och den nås vanligtvis med hjälp av MySQL-kod. Det låter kanske komplicerat, men det är som en uppsättning instruktioner som du kan använda för att göra ändringar på din webbplats bakom kulisserna.

I den här artikeln ska vi lära dig hur du använder MySQL för att skapa ett helt nytt administratörskonto för din webbplats, precis som att få en ny nyckel till ditt hus. På så sätt kan du låsa ute hackarna och ta tillbaka kontrollen.

How to Add an Admin User to the WordPress Database via MySQL

Varför ska man add to en Admin-användare till WordPress Database via MySQL?

Vi runnade en gång på en issue där en användares site hackades och deras admin account blev borttaget från databasen. Detta låste dem ute från deras website i WordPress.

Vi kunde hjälpa dem att få tillgång till sin website genom att skapa en new admin användare direkt till WordPress-webbplatsen. Vi gjorde det med hjälp av phpMyAdmin, ett webbaserat verktyg som allow you att hantera MySQL databaser med hjälp av din web browser.

Om du är utelåst från ditt admin area i WordPress på grund av hackare eller för att du helt enkelt har glömt ditt password, kan du göra samma sak.

Du bör dock alltid göra en backup av din database innan du utför några MySQL edits. När du sedan kan logga in på din website igen, kan du behöva följa vår guide för nybörjare för att fixa din hackade WordPress site.

Med detta sagt, låt oss ta en titt på hur man addar en admin-användare till WordPress database via MySQL.

Lägga till en admin-användare i WordPress Database med phpMyAdmin

phpMyAdmin kommer förinstallerat med de flesta högst upp WordPress webbhotell. You can find it in the Databases section of your hosting account’s cPanel dashboard.

Här är en skärmdump från Bluehost-kontrollpanelen:

Selecting phpMyAdmin on cPanel

Om du klickar på ikonen öppnas phpMyAdmin-gränssnittet. You need to select your WordPress database from the left column.

Därefter kommer phpMyAdmin att visa alla tabeller i din WordPress database. Du kommer att göra ändringar i tabellerna wp_users och wp_usermeta.

You Will Be Making Changes to the wp_users and wp_usermeta Tables

Lägga till en användare i wp_users-tabellen

Först måste du hitta tabellen wp_users och clicka på den. Då visas de användare som för närvarande finns i tabellen.

Notice in the screenshot below that there are two user ID:s in our demo website’s table, 1 and 2. When we create a new user for our demo site, this ID needs to be unique, so we’ll type the number 3.

Du måste clicka på tabben ”Insert” högst upp på vyn så att du kan inserta informationen för en ny användare.

Click the Insert Tab

Add to följande information till fälten i formuläret Infoga:

  • ID:n: välj ett unikt nummer (i vårt exempel använder vi 3)
  • user_login: användarnamnet som ska användas vidlogging
  • user_pass: add a password, och se till att välja MD5 i funktionsmenyn (se screenshot under)
  • user_nicename: användarens fullständiga namn eller smeknamn
  • user_email: användarens email address
  • user_url: adressen till din website
  • user_registered: select det datum och den tid då användaren registrerades med hjälp av kalendern
  • user_activation_key: lämna tomt
  • user_status: sätt detta till 0
  • display_name: användarens fullständiga namn eller displaynamn
Fill In the Fields for the New User

När du har slutfört, se till att du klickar på knappen ”Go” för att lagra den nya användaren.

Lägga till en användare i wp_usermeta-tabellen

Nu måste du hitta tabellen wp_usermeta och clicka på den. Efter det ska du klicka på tabben ”Insert” som du gjorde i föregående steg.

Följaktligen måste du add to följande information till formuläret Infoga:

  • unmeta_id: lämna detta tomt (det kommer att genereras automatiskt)
  • user_id: det ID:n för användaren som du använde i föregående steg
  • meta_key: detta bör vara wp_capabilities
  • meta_value: insert this: a:1:{s:13:"administratör";s:1:"1";}
Fill In the Fields for the New User

När du sedan rullar nedåt hittar du fält för en andra row. Du måste add to följande information:

  • unmeta_id: lämna detta tomt (det kommer att genereras automatiskt)
  • user_id: det ID:n för användaren som du använde i de föregående stegen
  • meta_key: du måste enter wp_user_level
  • meta_värde: 10
Fill In the Fields for the New User

När du har slutfört att enter informationen i fälten måste du klicka på knappen ”Go”. Grattis, du har nu skapat ett nytt användarnamn för administratörer!

Nu bör du kunna logga in på din WordPress admin area med användarnamn och password som du angav för den här användaren.

Så snart du loggar in måste du navigera till Användare ” Alla användare och sedan klicka på användarnamnet du just skapat.

Navigate to Users » All Users and Edit the New User

Nu, utan att ändra något, rullar du längst ner på sidan och klickar på knappen ”Save”.

This will allow WordPress to clean up the user you just created and add to some extra information that is needed.

Lägga till en Admin-användare i WordPress Database med hjälp av en SQL-sökning

Om du är utvecklare kan du påskynda processen med hjälp av kod.

Du behöver bara lägga in denna SQL-fråga i din database:

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');

Se till att du ändrar ”databasename” till den database du arbetar med.

Glöm inte heller att ändra de andra värdena till dem du vill ha för den nya användaren, som vi förklarade i den första metoden.

Drop This SQL Query Into Your Database

Expertguider om vad du ska göra när du är utelåst från WordPress Admin

Nu när du vet hur man lägger till en admin användare via MySQL, kanske du gillar att se några artiklar om hur du fixar din website när du är utelåst från WordPress admin area.

Vi hoppas att denna tutorial hjälpte dig att lära dig hur du lägger till en administratörsanvändare till WordPress-databasen via MySQL. You may also want to see our ultimate WordPress security guide or our list of common WordPress errors and how to fix them.

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.

Avslöjande: Vårt innehåll stöds av våra läsare. Det innebär att om du klickar på några av våra länkar, kan vi tjäna en provision. Se hur WPBeginner finansieras, varför det är viktigt, och hur du kan stödja oss. Här är vår editoriala process.

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.

Den ultimata WordPress-verktygslådan

Få GRATIS tillgång till vår verktygslåda - en samling WordPress-relaterade produkter och resurser som varje professionell användare bör ha!

Reader Interactions

240 kommentarerLämna ett svar

  1. 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!

      Administratör

  2. 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

  3. An

    This guide just made my life so much easier!
    I don’t know you but I love you!
    Thanks!

  4. 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

  5. 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.

      Administratör

  6. 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.

      Administratör

  7. 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!

      Administratör

  8. 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!

  9. Lucas

    Thank you a lot. You save my life, bro. thks

    • WPBeginner Support

      Glad our guide was helpful!

      Administratör

  10. 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.

  11. Sam

    Excellent article. Forgot login details after years of hiatus.

    • WPBeginner Support

      Glad our article was able to help!

      Administratör

  12. daniele

    done but is not working for me. I created an account but wo see it as subscriber account not an admin.

  13. 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 :)

      Administratör

  14. Farkas Tibor

    Thanks, it saved me from a lot of work.

    • WPBeginner Support

      Glad our guide was helpful! :)

      Administratör

  15. 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.

  16. 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?

  17. 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 :)

      Administratör

  18. 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 :)

      Administratör

  19. 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.

      Administratör

  20. Kyle Eggleston

    Excellent, useful tutorial. Thanks for publishing.

    • WPBeginner Support

      You’re welcome :)

      Administratör

  21. 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 :)

      Administratör

  22. 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 :)

      Administratör

    • Jan

      Yes this also worked me, Many Thanks!

  23. 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

      Administratör

  24. 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

      Administratör

  25. 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 :)

      Administratör

  26. Alexander Mtembenuzeni

    This was really helpful. Thank you!

    • WPBeginner Support

      Glad our post was helpful :)

      Administratör

  27. Anisha

    Working on this for days. Thank you…

    • WPBeginner Support

      Glad our article could help you :)

      Administratör

  28. 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?

  29. Asif

    Thank you very much!

    • WPBeginner Support

      You’re welcome :)

      Administratör

  30. 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.

      Administratör

  31. 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

  32. 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!

  33. 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 :)

      Administratör

  34. stephane

    You Save my Life. Thank you so much!

    • WPBeginner Support

      Glad our article could be helpful :)

      Administratör

  35. Gina

    EXCELLENT tutorial. Thank you so much!

  36. mahmud

    many many thanks bro. you are genius.

  37. Punam

    Many Many thank.. it is very helpful to me and my site work perfectly…

  38. 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!

  39. 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?

  40. Cavid Muradov

    You helped my life, thank you very much.

  41. 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.

  42. Chakerz

    Hi,

    change ”wp_” to your installation prefix !!

    :-)

  43. 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.

  44. JOEL

    Very good, great info. The SQL worked super fast so thumbs up!

  45. 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

  46. Jules

    Thank you, this has been very helpful.

  47. 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.

  48. 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..

  49. James Denning

    I have the same problem. No matter what I do the user does not have any privliges

  50. 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!

Lämna ett svar

Tack för att du väljer att lämna en kommentar. Tänk på att alla kommentarer modereras enligt våra policy för kommentarer, och din e-postadress kommer INTE att publiceras. Vänligen använd INTE nyckelord i namnfältet. Låt oss ha en personlig och meningsfull konversation.