You are here

20 February 2019

This snippet shows how to create a new database and user with assigning permissions of the newly created database to the user. In this example I use database name as user name for clarity and consistency.

Source code viewer
  1. CREATE DATABASE `database_name` CHARACTER SET utf8 COLLATE utf8_general_ci;
  2. CREATE USER 'database_name'@'localhost' IDENTIFIED BY 'password';
  3. GRANT ALL PRIVILEGES ON `database_name`.* TO 'database_name'@'localhost';
Programming Language: MySQL