Create Database and User - SQL Commands

Instructions to create a database and user using SQL commands.

  • Create Database: Create a database and set it as the active database.
    CREATE DATABASE DATABASENAME;
    USE DATABASENAME;
  • Create User: Create user accounts with passwords.
    CREATE USER XXXXX IDENTIFIED BY 'XXXXXXXXXXX';
    CREATE USER PLACEHOLDER IDENTIFIED BY 'PLACEHOLDER';
    CREATE USER 'PLACEHOLDER'@'localhost' IDENTIFIED BY 'PLACEHOLDER';
  • Grant Privileges: Grant privileges to the created users.
    GRANT ALL PRIVILEGES ON *.* TO 'PLACEHOLDER'@'localhost';
    GRANT ALL privileges ON `XXXXX`.* TO XXXX@localhost IDENTIFIED BY 'XXXXXXXXXXX';
    GRANT ALL PRIVILEGES ON *.* TO 'PLACEHOLDER'@'%' WITH GRANT OPTION;
    GRANT ALL privileges ON PLACEHOLDER.* TO PLACEHOLDER@localhost IDENTIFIED BY 'PLACEHOLDER';
  • Chown and Permissions: Set ownership and permissions for files and directories.
    chown apache:apache -R * # Let Apache be owner
    find . -type d -exec chmod 755 {} \; # Change directory permissions rwxr-xr-x
    find . -type f -exec chmod 644 {} \; # Change file permissions rw-r--r--
  • Show All Users: View a list of all MySQL users.
    SELECT User, Host, Password FROM mysql.user;