CREATE, ALTER, GRANT and DROP users to control access in MariaDB.
Creating accounts, setting authentication, granting or revoking privileges, altering credentials, and safely removing users together form MariaDB user management. Each step protects business data in tables such as Customers
, Orders
, and Products
.
Run CREATE USER
with a user name, optional host, and authentication method. Providing a host avoids duplicate, unmanaged accounts.
CREATE USER 'app_reader'@'%' IDENTIFIED BY 'S3cure!';
Use GRANT
to assign the least-privilege set, targeting the exact schema or table.
GRANT SELECT ON ecommerce.Customers TO 'app_reader'@'%';
ALTER USER
modifies credentials instantly. Require a strong password policy to prevent weak logins.
ALTER USER 'app_reader'@'%' IDENTIFIED BY 'N3wPw!2024';
DROP USER
deletes the account and any privilege rows in one step.
DROP USER IF EXISTS 'app_reader'@'%';
Query the INFORMATION_SCHEMA.USER_PRIVILEGES
or run SHOW GRANTS
to audit access levels regularly.
SHOW GRANTS FOR 'app_reader'@'%';
Apply least privilege, separate service accounts from humans, rotate passwords, and enable audit_log
for traceability.
root
in applications?Using the superuser in code risks accidental data loss and security breaches. Always create scoped accounts.
Yes. Use RENAME USER 'old'@'host' TO 'new'@'host';
which keeps existing privileges.
No. GRANT, REVOKE, CREATE USER, and DROP USER auto-reload privilege tables in MariaDB.
Add PASSWORD EXPIRE
to ALTER USER
. The session will prompt for a new password on first connection.