What this is
This guide shows how to create a MySQL database and a dedicated user for an application.
What it is for
- Keep each app isolated with its own credentials
- Avoid using root for applications
Prerequisites
- MySQL/MariaDB installed
- SSH + sudo
Step-by-step
Step 1) Open MySQL shell
sudo mysql
Step 2) Create database
CREATE DATABASE appdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
What it does: Creates a database with modern UTF-8 support.
Step 3) Create user (local only recommended)
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'STRONG_PASSWORD_HERE';
Step 4) Grant privileges
GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'localhost';
FLUSH PRIVILEGES;
Step 5) Verify
SHOW DATABASES;
EXIT;
Test login as the new user:
mysql -u appuser -p -h 127.0.0.1 appdb
Expected output: mysql> prompt after entering the password.
Warnings & notes
- Do not use weak passwords.
- Avoid creating users with
'%'(remote access) unless necessary and protected.
Conclusion
You now have a dedicated DB and user for your application. This is safer and easier to manage than sharing root credentials.