Knowledge Base

Managing Databases via SSH

Managing Databases via SSH

 How to Delete a Database via SSH

To delete a database using SSH, follow these steps:

  1. Backup the database first
    Run the following command in your SSH terminal (replace username and database with your actual values):

     
    mysqldump --password username_database > username_database.db

    Enter your cPanel password when prompted.

  2. Connect to MySQL

     
    mysql -u username -p
  3. Verify the database exists

     
    SHOW DATABASES LIKE "username_database";
  4. Delete (Drop) the database

     
    DROP DATABASE username_database;
  5. Confirm deletion

     
    SHOW DATABASES LIKE "username_database";

    The result should be an empty set — meaning the database has been successfully removed.

 For detailed syntax, refer to MySQL’s official DROP DATABASE documentation.

 

 How to Drop One or Multiple Users

You can remove user accounts (and their privileges) using the DROP USER statement.

Syntax:

 


DROP USER 'user'@'host';

Example (single user):

 


DROP USER 'snappy01'@'localhost';

Example (multiple users):

 


DROP USER 'snappy01'@'localhost', 'snappy02'@'localhost';

 Deleting a user will also remove all privileges associated with that account.


 How to Grant Privileges in MySQL

To grant permissions to a user, you must have CREATE USER and GRANT privileges.

Syntax:

 


GRANT permission1, permission2 ON database_name TO 'user'@'localhost';

Example:

 


GRANT SELECT, INSERT, DELETE ON example_db TO 'snappy02'@'localhost';

This gives the user snappy02 the ability to select, insert, and delete records within the example_db database.


 How to View User Privileges

To check a user’s assigned privileges:

Syntax:

 


SHOW GRANTS FOR 'database_user'@'localhost';

Example:

 


SHOW GRANTS FOR 'snappy02'@'localhost';

Sample Output:

+------------------------------------------------------------------+
| Grants for snappy02@localhost |
+------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `snappy02`@`localhost` |
| GRANT SELECT, INSERT, UPDATE ON `example_db`.* TO `snappy02`@`localhost` |
+------------------------------------------------------------------+



 

 

Please rate this article to help us improve our Knowledge Base.

0 0