Account Lock — SQL Technical Interview Questions & Answers

Account Lock

Account Lock

  • ALTER USER 'asha'@'localhost' ACCOUNT LOCK; stops that MySQL user from logging in. Unlock with ACCOUNT UNLOCK. This is a user account, not a table row.
  • Use it when a intern leaves or a password leak happens — lock first, rotate password, unlock if needed.
  • Trap: confusing ACCOUNT LOCK with LOCK TABLES.
  • On the example next to this theory: Account Lock: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

Technical Interview Tip: ALTER USER 'asha'@'localhost' ACCOUNT LOCK;

Code Examples for Account Lock

Account Lock — sample query

-- Account Lock
CREATE TABLE demo (
  id INTEGER PRIMARY KEY,
  label TEXT NOT NULL,
  qty INTEGER DEFAULT 0
);
INSERT INTO demo (id, label, qty) VALUES
  (1, 'alpha', 2),
  (2, 'beta', 5);
SELECT label, qty FROM demo WHERE qty >= 2 ORDER BY qty DESC;

Account Lock: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

How to Explain Account Lock to an Interviewer

What does ACCOUNT LOCK do?

Blocks that MySQL user from connecting