← Back to MySQL Course | Chapter 18: User Management & Security | Lesson 4 of 6

DROP USER

DROP USER किसी का account बंद करने और उनका key card हमेशा के लिए ले लेने जैसा है।
Syntax
sql
DROP USER [IF EXISTS] 'username'@'host';

एक User कैसे Drop करें

DROP USER permanently एक ऐसा account delete करता है जिसे अब database तक किसी access की ज़रूरत नहीं, login और इसे assign की गई हर privilege दोनों हटाते हुए।

उदाहरण: How to Drop a User

sql
DROP USER 'app_user'@'localhost';

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

एक साथ कई Users Drop करना

उन्हें commas से separated list करके एक single statement में कई accounts drop किए जा सकते हैं, जो अलग commands issue करने के बजाय एक साथ कई stale accounts साफ करते समय समय बचाता है।

उदाहरण: Dropping Multiple Users at Once

sql
DROP USER 'app_user'@'localhost', 'temp_user'@'localhost';

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

IF EXISTS Safety Check

IF EXISTS add करना MySQL को एक error throw करने से रोकता है अगर आप एक पहले से गए user को drop करने की कोशिश करें, जो cleanup scripts को एक से ज़्यादा बार चलने पर बीच में fail होने से बचाता है।

उदाहरण: The IF EXISTS Safety Check

sql
DROP USER IF EXISTS 'app_user'@'localhost';

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Users Drop करना और Security Cleanup

एक user हटाने के बाद, production systems पर privilege tables reload करना recommended है यह सुनिश्चित करने के लिए कि account का access तुरंत पूरी तरह revoke हो जाए बजाय एक cached state में बने रहने के।

उदाहरण: Dropping Users and Security Cleanup

sql
DROP USER 'app_user'@'localhost';
FLUSH PRIVILEGES;

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Users हटाने के लिए Best Practices

किसी account को drop करने से पहले, exact username और host combination confirm करने के लिए user list search करना गलत account delete होने की costly mistake से बचाने में मदद करता है, खासकर similar usernames exist करते समय।

उदाहरण: Best Practices for Removing Users

sql
SELECT user, host FROM mysql.user WHERE user = 'app_user';
DROP USER 'app_user'@'localhost';

⚠️ This is MySQL-specific syntax. It cannot run in the browser editor. Practice this on your local MySQL installation.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. गलत host हिस्से वाले एक user को drop करना, ताकि account न मिले।
  2. यह मान लेना कि user की tables और data भी हट जाएँगे, जबकि सिर्फ account जाता है और इसके बनाए objects रहते हैं।
  3. एक ऐसे account को drop करना जो अभी भी connected है, जबकि existing sessions disconnect होने तक चलती रहती हैं।
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.