brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: SHOW GRANTS FOR checks what a database user can really do

Database
~/tips/tip-database-show-grants-for-user

SHOW GRANTS FOR 'app'@'localhost';

Lists the exact privileges of one MySQL or MariaDB account so you can spot too-wide rights.

A MySQL or MariaDB application user often has more rights than anyone remembers. I check it in one statement.

SHOW GRANTS FOR 'app'@'localhost';
SELECT user, host FROM mysql.user ORDER BY user;

The first line lists every privilege of that account. Anything beyond the database the app needs, such as ALL PRIVILEGES ON *.* or GRANT OPTION, is worth removing with REVOKE.

An account is a user and host pair. 'app'@'%' and 'app'@'localhost' are two separate accounts with separate grants, so look at the second query to see which ones exist. SHOW GRANTS on its own shows your own account.

Further reading: MySQL Reference Manual: SHOW GRANTS

More Database tips mariadb -e 'CREATE DATABASE IF NOT EXISTS blog' mariadb-dump --no-create-info --insert-ignore shop orders > orders-rows.sql SELECT table_schema, table_name, CHECKSUM TABLE shop.orders; services: All Database tips (53) All topics

Link