Setting up a MySQL database for a new project, you basically have three things to do:

  • Create a database
  • Create a standalone database user for the database for security purposes
  • Grant privileges of the database to the new user
1
2
3
4
5
6
-- Create Database
CREATE DATABASE IF NOT EXISTS `<database_name>` CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
-- Create User
CREATE USER '<username>'@'%' IDENTIFIED BY '<password>';
-- Grant Privileges
GRANT ALL PRIVILEGES ON `<database_name>`.* TO '<username>'@'%';