Create MySQL database, user and Grant Permissions on EC2, VPS, Cloud Servers

Linux commands

Learn how to create a MySQL database, set up a new user, and grant permissions on EC2, VPS, or cloud servers.
Before following these steps, ensure MySQL is installed on your server.

1. Access the Server via SSH

2. Log in to MySQL

mysql -u root -p

3. Create a New Database

CREATE DATABASE your_database_name;

4. Create a New MySQL User

CREATE USER 'your_username'@'%' IDENTIFIED BY 'your_password';

5. Grant Permissions to the User

GRANT ALL PRIVILEGES ON your_database_name.* TO 'your_username'@'%';

6. Apply Changes

FLUSH PRIVILEGES;

7. Exit the MySQL Shell

EXIT;