mysql给数据库添加用户_如何通过MySQL将管理员用户添加到WordPress数据库

mysql给数据库添加用户

Few days ago, we ran into an issue where a user’s site got hacked and their admin account was deleted from the database. This locked them out of their site without any other entry. We went in to the phpMyAdmin and created a new admin user to grant them access. In this article, we will show you a step by step guide on how to create an admin user in WordPress Database via MySQL.

几天前,我们遇到了一个问题,即用户的网站被黑,其管理员帐户已从数据库中删除。 这将他们锁定在他们的站点之外,而没有任何其他条目。 我们进入phpMyAdmin并创建了一个新的admin用户来授予他们访问权限。 在本文中,我们将向您逐步介绍如何通过MySQL在WordPress数据库中创建管理员用户的指南。

Note: You should always make a backup of your database before performing any MySQL edits. This tutorial requires basic understanding of how phpMyAdmin works.

注意:在执行任何MySQL编辑之前,您应该始终对数据库进行备份。 本教程需要基本了解phpMyAdmin的工作方式。

影片教学 (Video Tutorial)

演示地址

If you don’t like the video or need more instructions, then continue reading.

如果您不喜欢该视频或需要更多说明,请继续阅读。

First, you need to login to phpMyAdmin and locate your WordPress database. (Below is a screenshot of a HostGator cPanel)

首先,您需要登录到phpMyAdmin并找到您的WordPress数据库。 (下面是HostGator cPanel的屏幕截图)

cPanel phpMyAdmin

Once you are in, we will be making changes to the wp_users and wp_usermeta tables. Lets go ahead and click on wp_users table.

进入后,我们将对wp_users和wp_usermeta表进行更改。 让我们继续,然后单击wp_users表。

phpMyAdmin wp_users table

We need to insert our new admin user’s information, so click on the Insert tab like it shows in the image above. In the insert form, add the following:

我们需要插入新管理员用户的信息,因此请单击“插入”选项卡,如上图所示。 在插入表单中,添加以下内容:

  • ID – pick a number (in our example, we will use the number 4).ID –选择一个数字(在我们的示例中,我们将使用数字4)。
  • user_login – insert the username you want to use to access the WordPress Dashboard.user_login –插入要用于访问WordPress仪表板的用户名。
  • user_pass – add a password for this username. Make sure to select MD5 in the functions menu (Refer to the screenshot below).user_pass –为此用户名添加密码。 确保在功能菜单中选择MD5(请参阅下面的屏幕截图)。
  • user_nicename – put a nickname or something else that you would like to refer yourself as.user_nicename –输入昵称或其他您想引用的名称。
  • user_email – add the email you want to associate with this account.user_email –添加要与此帐户关联的电子邮件。
  • user_url – this would be the url to your website.user_url –这是您网站的网址。
  • user_registered – select the date/time for when this user is registered.user_registered –选择该用户注册的日期/时间。
  • user_status – set this to 0.user_status –设置为0。
  • display_name – put the name you like to display for this user on the site (it can be your user_nicename value as well).display_name –在该网站上放置您要为此用户显示的名称(也可以是您的user_nicename值)。
  • Click on the Go Button

    点击执行按钮

phpMyAdmin Insert values in wp_users table

Next we are going to have to add the values to wp_usermeta table. Click on the wp_usermeta table and then click on the Insert tab just like the previous step. Then add the following information to the insert form:

接下来,我们将不得不将值添加到wp_usermeta表中。 单击wp_usermeta表,然后像上一步一样单击Insert选项卡。 然后将以下信息添加到插入表单:

  • unmeta_id – leave this blank (it will be auto-generated)unmeta_id –保留此空白(它将自动生成)
  • user_id – this will be the id of the user you created in the previous step. Remember we picked 4.user_id –这是您在上一步中创建的用户的ID。 记住我们选了4。
  • meta_key – this should be wp_capabilitiesmeta_key –这应该是wp_capabilities
  • meta_value – insert this: meta_value –插入: a:1:{s:13:"administrator";s:1:"1";}a:1:{s:13:"administrator";s:1:"1";}

Insert another row with the following information:

插入另一行,并提供以下信息:

  • unmeta_id – leave this blank (it will be auto-generated)unmeta_id –保留此空白(它将自动生成)
  • user_id – this will be the id of the user you created in the previous step. Remember we picked 4.user_id –这是您在上一步中创建的用户的ID。 记住我们选了4。
  • meta_key – this should be wp_user_levelmeta_key –这应该是wp_user_level
  • meta_value – 10meta_value – 10

Then click on the Go button, and you have created yourself a new username. Now you should be able to login to your wp-admin with the username and password you specified for this user. Once logged in, click on Users and edit the username you just created. Go down and click on the Save button (you don’t have to change anything). This will allow WordPress to go through and add some more information and clean-up the user we just added.

然后单击“执行”按钮,您已经为自己创建了一个新的用户名。 现在,您应该可以使用为此用户指定的用户名和密码登录到wp-admin。 登录后,单击“用户”并编辑您刚创建的用户名。 向下并单击“保存”按钮(您无需更改任何内容)。 这将使WordPress能够完成并添加更多信息,并清理刚刚添加的用户。

SQL查询 (SQL query)

For developers who want to speed this process up, you can simply drop this SQL query in your database.

对于想要加快此过程的开发人员,您只需在数据库中删除此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 ('4', 'demo', MD5('demo'), 'Your Name', 'test@yourdomain.com', 'http://www.test.com/', '2011-06-07 00:00:00', '', '0', 'Your Name');


INSERT INTO `databasename`.`wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '4', '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, '4', 'wp_user_level', '10');

Remember to change the databasename to the database you are working with. Also don’t forget to change the appropriate values.

切记将数据库名称更改为您正在使用的数据库。 同样不要忘记更改适当的值。

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-add-an-admin-user-to-the-wordpress-database-via-mysql/

mysql给数据库添加用户

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值