Create MySQL database with SSH command



Database in MySQL can be created by using the phpmyadmin interface but some times if there is no installation of the phpmyadmin on the server but MySQL is there, then you can create the database by using the SSH Commandline for that you should have the root access of the server. Here in this post I am trying to describe that how we can create the database by using the SSH Command line, assuming that you have the root access of the server.

Here are the steps to create the Database and the Database user by using the SSH Command

Step 1. First of all open the Terminal and connect to the server by using the syntax below:

ssh username@hostname

You will be prompted for a password.

Step 2. After the login to the server now login for the mysql using the command below:

mysql -u root -p

You will be prompted for a password.

Step 3. After successfull login now use the following command to create the database.

CREATE DATABASE your_database_name;

Step 4. By default there is the privileges to the database of the root user (or whoever by which you have logged in). If you want to provide the access to the different user, use the following commands

GRANT USAGE ON your_database_name.* to new_user@localhost IDENTIFIED BY 'new_user_passwd';

Step 5. Now for providing all priviliges to the newly created user use the following command

GRANT ALL ON your_database_name.* to new_user@localhost;

Step 6. Now flush the priviliges to take the effect of the user priviliges use the below command
FLUSH PRIVILEGES;

Step 7. Now your new user can log in and access the database with the full priviliges:

mysql -u new_user -p 'new_user_passwd' your_database_name

Now you can check the database and can import the tables into the newly created database.

Looking for how to Import or Export database by using the SSH? Click Here.

Now you have done. Hope it helps, Thanks for reading.