If you need to create a database for your website there are multiple ways to do it. In this guide, you can learn how to create a MySQL database using the command line.
Create a MySQL Database Using CLI
If you are running a Linux server with MySQL but no cPanel, you can simply use MySQL commands to create a MySQL database, database user, and password, as well as, assign all privileges to the user for the database.
- SSH into your server.
- Log into MySQL as the root user.
- Create a new database user:
GRANT ALL PRIVILEGES ON *.* TO 'db_user'@'localhost' IDENTIFIED BY '[email protected]$w0rd123!';NOTE: Be sure to modify
db_userwith the actual name, you would like to give the database user, as well as,
[email protected]$w0rd123!with the password to be given to the user.
- Log out of MySQL by typing:
- Log in as the new database user you just created:
mysql -u db_user -pNOTE: Be sure to modify
db_userwith the actual database user name.
Then, type the new database user’s password and press Enter.
- Create a new database:
CREATE DATABASE db_name;NOTE: Be sure to modify
db_namewith the actual name you would like to give the database.
Congratulations! Now, you know how to create a MySQL database from the command line. Want to learn more about database management? Check out our guide on How to Import MySQL Databases in Command Line.