Magento : ajouter un administrateur avec MySQL

Version courte

Version détaillée

Je me suis retrouvé récemment à devoir me connecter à la console d’admin d’un Magento 1, dont je ne connaissait aucun identifiant. J’avais tout juste accès à MySQL. Sur internet, la plupart des articles proposent de passer par bin/magento, qui n’était pas utilisable dans mon cas. Mais j’ai finalement trouvé la solution chez Webnoo :

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

SET @SALT = "ls";
SET @PASS = CONCAT(MD5(CONCAT( @SALT , "adminpassword") ), 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 ('AdminFirstname','AdminLastname','admin@email.com','adminusername',@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 = 'adminusername'),'AdminFirstname');

UNLOCK TABLES;

 

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

SET @SALT = "ls";
SET @PASS = CONCAT(MD5(CONCAT( @SALT , "adminpassword") ), 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 ('AdminFirstname','AdminLastname','admin@email.com','adminusername',@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 = 'adminusername'),'AdminFirstname');

UNLOCK TABLES;

Powered by TLDR