Updated: 28 September 2026 · Applies to: MariaDB 10.6 to 11.4 and MySQL 8
On a VPS or dedicated server, grant a user access to a database from the MySQL/MariaDB command line.
Steps
- Open the client as root:
mysql(ormysql -u root -p). - Create the user if it does not exist:
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'Strong-Password';
- Grant privileges on the database:
GRANT ALL PRIVILEGES ON shopdb.* TO 'appuser'@'localhost';
- Check:
SHOW GRANTS FOR 'appuser'@'localhost';
Note the quotes: the database name is written without quotes (or with backticks, `shopdb`.*), while the user and host are in single quotes.
Tip: Grant only what the application needs, for example SELECT, INSERT, UPDATE, DELETE, for read-and-write access without the right to change tables. On cPanel accounts, use Databases › Manage My Databases instead, so cPanel keeps track of the user.