Create Database, Create Database User and Set Database Privileges for particular User Using SSH

0
96
views
Advertisement

In this post We’ll let you know how to Create Database using SSH, how to Create Database User using SSH and also how to Grant or Revoke Privileges for a particular user using SSH.

To perform database opration using SSH first of all you need to login on mysql using following command. After enter below command it’ll ask for the password of you database root user. here root is a user name of your database.

mysql -u root -p

After Loged in on mysql run below command for create new database. Before run below command you need to replace “YOUR_DATABASE_NAME” with your Database name.

CREATE DATABASE YOUR_DATABASE_NAME;

Once your database has been created. you need to assign User for that database. So, Before a assign user to database let just see how to create database user. To create database user you just need to run below commans. Before run this command you just need to replace “DATABASE_USERNAME” with your database user and “PASSWORD_OF_THIS_USER” with your database password.

CREATE USER 'DATABASE_USERNAME'@'localhost' IDENTIFIED BY 'PASSWORD_OF_THIS_USER';

Once your successfully create user run following command for GRANT Privileges to user for your database. Here you just need to replace “YOUR_DATABASE_NAME” with your database name and “DATABASE_USERNAME” with the user you want to grant privileges.

GRANT ALL PRIVILEGES ON YOUR_DATABASE_NAME . * TO 'DATABASE_USERNAME'@'localhost';

In case if you want to Revoke privileges for particular user for your database then below command we’ll helps you on this. Replace “YOUR_DATABASE_NAME” with your database name and “DATABASE_USERNAME” with the user you want to revoke privileges.

REVOKE ALL PRIVILEGES ON YOUR_DATABASE_NAME . * FROM 'DATABASE_USERNAME'@'localhost';

If you perform any command related to privileges then you have to FLUSH PRIVILEGES for reflect that changes. Below command is helps to FLUSH PRIVILEGES.

FLUSH PRIVILEGES;

We hope this post helped you to Create Database, Create Database User and Set Database Privileges for particular User Using SSH. Bookmark it for your future reference. Do comment below if you have any other questions or doubts.

P.S. Do share this post with your team.