Search Our Database
How to Create a New Database and New Database User Using Terminal
Create a New Database
Follow the steps below to create a new database and assign privileges to a user in MySQL. If the user doesn’t exist yet, instructions on creating a new user are provided further down.
Step 1: Log in to MySQL Client
First, log in to the MySQL client using the following command:
mysql -u root -p
Step 2: Create a New Database
Once logged in, use the following command to create a new database:
mysql> CREATE DATABASE 'databasename';
Step 3: Grant Privileges to a Database User
If the user already exists, you can grant the necessary privileges to that user using the following command:
mysql> GRANT ALL PRIVILEGES ON 'databasename'.* TO 'username'@'hostname' IDENTIFIED BY 'password'; mysql> FLUSH PRIVILEGES;
If the database user doesn’t exist yet, proceed to the tutorial below to create a new user.
Create a New Database User
Step 1: Log in to MySQL Client
Log in to the MySQL client with the following command:
mysql -u root -p
Step 2: Create a New User
Use the following command to create a new user:
mysql> CREATE USER 'new-username'@'localhost' IDENTIFIED BY 'password-for-new-account';
Extra: DirectAdmin MySQL Login
For DirectAdmin-based Linux servers, you can log in to MySQL using the DirectAdmin MySQL root account. This account information can be found in the following file:
/usr/local/DirectAdmin/conf/mysql.conf
Article Posted on 23 February 2020 by Louis