Add a Magento Admin User using SQL

Sometimes we aren’t able to access to our Magento admin panel. No fear! You can create a new admin user directly via DB.
Let’s suppose to create a user with name ‘AdminUser’, surname ‘Foobar’, email ‘’, username ‘myname’ and password ‘mypassword’.
Open a command line shell, connect to your MySQL DBMS and type the following commands:

LOCK TABLES `admin_role` WRITE , `admin_user` WRITE;

SET @SALT = “rp”;
SET @PASS = CONCAT(MD5(CONCAT( @SALT , “mypassword”) ), CONCAT(“:”, @SALT ));
SELECT @EXTRA := MAX(extra) FROM admin_user WHERE extra IS NOT NULL;

INSERT INTO `admin_user` (firstname,lastname,email,username,password,created,lognum,reload_acl_flag,is_active,extra,rp_token_created_at)
VALUES (‘AdminUser’,’Foobar’,’’,’myname’,@PASS,NOW(),0,0,1,@EXTRA,NOW());

INSERT INTO `admin_role` (parent_id,tree_level,sort_order,role_type,user_id,role_name)
VALUES (1,2,0,’U’,(SELECT user_id FROM admin_user WHERE username = ‘myname’),’AdminUser’);


Likewise you can put these commands into a script (for example ‘addadmin.sql’) and run it from command line.

Pay attention!

In this case, the queries structure is for MySQL; for other DBMS (e.g. PostgreSQL, SQLServer, etc.) it could be quiet different.

This procedure is valid for Magento 1.x; it has not been tested on Magento 2.x. Any update about it will be appreciated.

Leave a comment

Your email address will not be published. Required fields are marked *