Create a Database Using MySQL CLI

By | May 17, 2020
  1. SSH into your server.
  2. Log into MySQL as the root user.
  3. Create a new database user: GRANT ALL PRIVILEGES ON *.* TO 'db_user'@'localhost' IDENTIFIED BY 'P@s$w0rd123!';
    NOTE: Be sure to modify db_user with the actual name you would like to give the database user, as well as, P@s$w0rd123! with the password to be given to the user.
  4. Log out of MySQL by typing: \q.
  5. Log in as the new database user you just created: mysql -u db_user -p
    NOTE: Be sure to modify db_user with the actual database user name. Then, type the new database user’s password and press Enter.
  6. Create the new database: CREATE DATABASE db_name;
    NOTE: Be sure to modify db_name with the actual name you would like to give the database.