Gerrit user administation by SQL / Hack your own Gerrit

If you lost admin access to your own Gerrit instance it is pretty easy to add a user (the user must be able to login to gerrit web ui) to the admin group by using the Gerrit SQL interface and some basic SQL commands:

# first stop gerrit
# then start the SQL interface - you need console access and the site name
java -jar gerrit.war gsql -d ${site_name}
# now you should be logged in to the SQL interface
# show all tables
show tables;
# get the account_id for the user, who can log on
select * from accounts;
# get the group_id - the admin group_id is 1
select * from account_groups;
# get all groups
select * from account_group_members;
# insert the new administrator to the database
insert into account_group_members (account_id, group_id) values (user_id, group_id);