Create Database, Create Database User and Set Database Privileges for particular User Using SSH
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.
AI-Powered Recommended Articles
Essential MySQL Commands for Everyday Use
Learn the most useful MySQL commands for managing databases, tables, and data. From basic operations to advanced user management, this guide has it all!
Get Database Backup and Restore Database from Backup Using SSH(Terminal)
Learn how to take a backup and restore your Magento 2 database using SSH commands for secure management.
How to Run Direct SQL Query in Magento 2
Learn how to run direct SQL queries in Magento 2 for custom database operations and management.
How to Install Magento 2 Using Command Line
Learn how to install Magento 2 using the command line interface for a streamlined and flexible installation process.
Manage Git Repository in Magento 2
Learn how to manage a Git repository in Magento 2 for version control and proper source code management.
Migrate Data From Magento 1 to Magento 2
A comprehensive guide on migrating data from Magento 1 to Magento 2, including essential tools and techniques.