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

CREATE USER

एक user बनाना building में हर person को अपना key card देने जैसा है, बजाय सबके एक master key share करने के।
Syntax
sql
CREATE USER 'username'@'host' IDENTIFIED BY 'password';

एक नया User कैसे बनाएँ

आपके database से connect होने वाले हर person या application के लिए एक dedicated account बनाना, एक login share करने के बजाय, एक core security practice है — CREATE USER इसे set up करने के लिए एक username, एक host, और एक password लेता है।

उदाहरण: How to Create a New User

sql
CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'StrongPass123!';

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

Host Constraints Specify करना

एक host constraint specify करना exactly restrict करता है कि एक user कहाँ से connect करने के लिए allowed है, चाहे वह एक single IP address हो, एक specific domain, या एक wildcard — इसे lock down करना एक common attack surface बंद कर देता है।

उदाहरण: Specifying Host Constraints

sql
CREATE USER 'app_user'@'192.168.1.10' IDENTIFIED BY 'StrongPass123!';

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

Authentication Plugins के साथ Users बनाना

MySQL यह manage करने के लिए अलग-अलग authentication plugins support करता है कि passwords कैसे verify होते हैं, और आप creation time पर एक specific plugin चुन सकते हैं जो आपके organization की जो भी security policy माँगती है उससे match करे।

उदाहरण: Creating Users with Authentication Plugins

sql
CREATE USER 'app_user'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'StrongPass123!';

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

सभी Database Users List करना

अपने database में मौजूद accounts की पूरी list को regularly review करना — mysql system schema query करके — stale या भूले हुए accounts को एक security liability बनने से पहले पकड़ने में मदद करता है।

उदाहरण: Listing All Database Users

sql
SELECT user, host FROM mysql.user;

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

Password Expiry के साथ Users बनाना

एक newly created account के password को तुरंत expire होने पर force करने का मतलब है कि user को पहली बार login करते समय अपना खुद का password set करना ज़रूरी है, जो एक shared या default password को कभी लंबे समय इस्तेमाल होने से बचाता है।

उदाहरण: Creating Users with Password Expiry

sql
CREATE USER 'temp_user'@'localhost' IDENTIFIED BY 'TempPass123!' PASSWORD EXPIRE;

⚠️ 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 हिस्सा भूल जाना, जैसे app_user, और user@localhost को user@'%' से confuse करना।
  2. एक weak password इस्तेमाल करना, या इसे एक ऐसी script में लिखना जिसे दूसरे पढ़ सकें।
  3. एक user बनाना और उसके access होने की उम्मीद करना, जबकि एक नए user के पास आपके GRANT करने तक कोई privileges नहीं होतीं।
🔒

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.