Create User — SQL Technical Interview Questions & Answers
Create User
Create User
- Create User is about MySQL accounts, not table rows. Users are 'name'@'host'. CREATE USER, GRANT, ALTER USER … IDENTIFIED BY, DROP USER.
- SHOW GRANTS FOR CURRENT_USER; to see yourself. Don’t use root from the app. Lock/unlock is ACCOUNT LOCK.
- Trap: user@localhost vs user@% as two different accounts.
- On the example next to this theory: Create User: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
Technical Interview Tip: 'user'@'host', GRANT, not root from the app.
Code Examples for Create User
Create User — sample query
-- Create User
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;Create User: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
How to Explain Create User to an Interviewer
What is 'asha'@'localhost'?
A MySQL account Host is part of the identity