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 pricingRelated tutorials
How to migrate a database between servers
Move a MySQL or PostgreSQL database to a new server with minimal downtime, using dump and restore.
Updated 7/20/2026DatabasesHow to secure MongoDB with authentication
By default, MongoDB runs without a password. Here is how to enable authentication and create an admin user.
Updated 7/20/2026DatabasesHow to connect an app to a remote database
Allow access to a database from another server, securely: bind address, dedicated user and firewall.
Updated 7/20/2026