How do I connect as an administrator?
On Debian 13, Debian 12 and Ubuntu, the MariaDB root account logs in through the system root user, so run sudo mariadb. On Rocky Linux and AlmaLinux, run mariadb-secure-installation after installing and log in with the root password you set there. If root refuses you, see Fix "Access denied for user root@localhost". Debian 13 ships MariaDB 11.8, while Debian 12 and Ubuntu 24.04 ship the 10.11 series; the statements below work on all of them.
How do I create a user?
CREATE USER 'crm'@'localhost' IDENTIFIED BY 'Xq7-long-random-value';
An account is a name plus a host. 'crm'@'localhost' may connect only through the local socket; the same name from another address is a different account. Choose the narrowest host that works:
| Host part | Allows connections from |
|---|---|
'localhost' | The Unix socket on this machine |
'127.0.0.1' | TCP from this machine |
'203.0.113.40' | One remote machine |
'10.66.0.%' | A subnet, such as a VPN range |
'%' | Anywhere; avoid on public servers |
Use CREATE USER IF NOT EXISTS in scripts that may run twice.
How do I grant privileges?
Grant on the smallest scope: one database, sometimes one table. A typical web application needs data changes and schema migrations on its own database only:
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, INDEX, DROP, REFERENCES ON crm.* TO 'crm'@'localhost';
A reporting account needs much less:
CREATE USER 'bi_reader'@'10.66.0.%' IDENTIFIED BY 'another-random-value'; GRANT SELECT ON crm.* TO 'bi_reader'@'10.66.0.%'; GRANT SELECT (id, created_at, total) ON shop.orders TO 'bi_reader'@'10.66.0.%';
The last line shows column-level grants: the account may read three columns of one table and nothing else in that database. Grants take effect immediately; FLUSH PRIVILEGES is only needed after editing grant tables directly, which you should not do.
What should a backup account have?
Enough to read everything consistently, nothing to change it:
CREATE USER 'dumper'@'localhost' IDENTIFIED BY 'third-random-value'; GRANT SELECT, SHOW VIEW, TRIGGER, EVENT, LOCK TABLES, RELOAD, PROCESS ON *.* TO 'dumper'@'localhost';
For physical backups with mariabackup, recent MariaDB releases also need BINLOG MONITOR or REPLICA MONITOR depending on options; the mariabackup documentation lists the exact set for your version. The dump side of backups is covered in Back up data with rsync.
How do roles make this easier?
Roles bundle privileges so you grant them once and assign them to many people:
CREATE ROLE crm_readonly; GRANT SELECT ON crm.* TO crm_readonly; GRANT crm_readonly TO 'mila'@'localhost', 'tomasz'@'localhost'; SET DEFAULT ROLE crm_readonly FOR 'mila'@'localhost';
Without a default role, a user must run SET ROLE crm_readonly after connecting. Changing the role later changes rights for everyone who holds it.
How do remote accounts stay safe?
Machines here talk over public addresses, since private networks are not part of the offer, so encrypt and narrow every remote connection:
CREATE USER 'replica'@'198.51.100.12' IDENTIFIED BY 'fourth-random-value' REQUIRE SSL; ALTER USER 'crm'@'203.0.113.40' WITH MAX_USER_CONNECTIONS 40;
Also set bind-address in the server configuration to the public address only when remote access is needed, and allow port 3306 in the firewall from the partner address alone. A WireGuard tunnel between machines is an alternative that keeps the database listening on a private range.
How do I check and remove grants?
SHOW GRANTS FOR 'crm'@'localhost'; REVOKE DROP ON crm.* FROM 'crm'@'localhost'; SELECT user, host FROM mysql.user ORDER BY user; DROP USER 'old_api'@'%';
Review accounts every few months. An old account with '%' as its host and a forgotten password is a common way in. Sizing the database server itself is covered on MySQL servers.
Keep Reading
Fix "Access denied for user root@localhost"
Why MySQL or MariaDB refuses root on a fresh server, the socket authentication behind it, and safe ways to log in or reset the password.
OpenMySQL servers
Give InnoDB a buffer pool that holds your working set, NVMe for the redo log and no hypervisor between query and disk.
OpenDatabase servers
PostgreSQL, MongoDB, ClickHouse and other engines on machines picked by working set, write rate and core count.
OpenLinux user management
The full life of an account on a server: create, group, change, expire, lock, audit and delete, with the files behind each step.
OpenFAQ
Quick Answers
Run CREATE USER 'name'@'host' IDENTIFIED BY 'password', choosing the narrowest host that works.
No. GRANT, REVOKE and CREATE USER take effect immediately.
Grant only SELECT on the database, for example GRANT SELECT ON crm.* to the account.
Create the account with that machine's address as host, require SSL, set bind-address and allow port 3306 from that address only.
Run SHOW GRANTS FOR 'name'@'host'.