CloudLinux.ro
Databases

How to create a MySQL user and grant privileges

Updated 7/20/2026

For security, every application should use its own MySQL user with access only to its own database. Here is how.

1. Create the user

mysql -u root -p
CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'strong_password';

2. Create the database

CREATE DATABASE app_db;

3. Grant privileges

Only on the application's database:

GRANT ALL PRIVILEGES ON app_db.* TO 'app_user'@'localhost';
FLUSH PRIVILEGES;

4. Narrower privileges (recommended)

For an app that only reads and writes data, avoid ALL:

GRANT SELECT, INSERT, UPDATE, DELETE ON app_db.* TO 'app_user'@'localhost';

5. Check and revoke

SHOW GRANTS FOR 'app_user'@'localhost';
REVOKE ALL PRIVILEGES ON app_db.* FROM 'app_user'@'localhost';

For remote access, replace localhost with % or a specific IP, but first see the connect to a remote database guide for the security steps.

Put this guide into practice on your own VPS

EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.

See pricing

Related tutorials