Magento MySQL Script To Add New Admin User Programmatically By Custom Script

Hi Guys,

In Magento, you can add new admin user programmatically using custom PHP script.
You need to write some MySQL queries to database to create admin user.
To add new admin user, you can use the following code snippet:


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

SET @SALT = "rp";
SET @PASS = CONCAT(MD5(CONCAT( @SALT , "password123") ), 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 ('Firstname','Lastname','test@mail.com','myuser',@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 = 'newuser'),'Firstname');

UNLOCK TABLES;

———————————–OR——————————–
You can use the MySQL phpmyadmin console to user directly from database where you need to provide password as md5 encrypted which you can select from dropdown options.

Leave a Reply