1 mins read
How to Create a MySQL User and Grant Database Permissions
Guide on creating a MySQL user and assigning proper database permissions.
Kapag nagse-setup ka ng server or nagde-deploy ng application, huwag na huwag mong gamitin ang MySQL root user sa app mo.
Common mistake ’yan, lalo na sa beginners.
Ang tamang approach:
- Create a dedicated MySQL user
- Ibigay lang yung permissions na kailangan
- Mas secure, mas clean, mas professional
Let’s go step by step.
Login to MySQLh2
mysql -u root -pCreate a New MySQL Userh2
CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'strong_password';Example:
CREATE USER 'nehry'@'localhost' IDENTIFIED BY 'secret123';Create a Database (if not yet existing)h2
CREATE DATABASE system_db;Grant Permissions to the Userh2
GRANT ALL PRIVILEGES ON system_db.* TO 'nehry'@'localhost';Apply the Changesh2
FLUSH PRIVILEGES;Verify the User Permissionsh2
mysql -u nehry -p system_db(Optional) Grant Specific Permissions Onlyh2
GRANT SELECT, INSERT, UPDATE, DELETE ON system_db.* TO 'nehry'@'localhost';Common Mistakes to Avoidh2
- ❌ Using root user in application config
- ❌ Granting permissions on
*.* - ❌ Weak passwords
- ❌ Forgetting
FLUSH PRIVILEGES
Final Thoughtsh2
One app, one database user, limited permissions.
This simple practice goes a long way in securing your applications.