← Back to MySQL Course | Chapter 2: Databases & Tables | Lesson 1 of 7

CREATE DATABASE

CREATE DATABASE एक बिल्कुल नई खाली cabinet खरीदने और इसे एक नाम देने जैसा है, आपकी tables रखने के लिए तैयार।
Syntax
sql
CREATE DATABASE [IF NOT EXISTS] database_name;

Basic Database Creation

CREATE DATABASE के बाद एक name आपकी tables के लिए एक नया logical container allocate करता है; नाम उस server instance पर unique होना ज़रूरी है, और MySQL बिना किसी safeguard के duplicates को पूरी तरह reject कर देता है।

उदाहरण: Basic Database Creation

sql
CREATE DATABASE shop;

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

Databases को Safely बनाना

CREATE DATABASE के बाद IF NOT EXISTS add करना statement को idempotent बना देता है — पहले से exist करने वाली एक database पर इसे फिर चलाना एक hard error के बजाय एक warning produce करता है, जो एक से ज़्यादा बार चलाई गई setup scripts में ज़रूरी है।

उदाहरण: Safely Creating Databases

sql
CREATE DATABASE IF NOT EXISTS shop;

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

Character Sets के साथ बनाना

database बनाते समय CHARACTER SET utf8mb4 specify करना ensure करता है कि यह पूरी Unicode range store कर सके, emoji और कई non-Latin scripts सहित — MySQL में पुराना utf8 alias असल में एक 3-byte subset है जो नहीं कर सकता।

उदाहरण: Creating with Character Sets

sql
CREATE DATABASE shop CHARACTER SET utf8mb4;

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

Collation Rules Specify करना

Collation rules decide करते हैं कि text comparisons और sorting case-sensitive या accent-sensitive हैं या नहीं; आपके application की language के लिए गलत collation चुनना बाद में search results को subtly गलत बना सकता है।

उदाहरण: Specifying Collation Rules

sql
CREATE DATABASE shop CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

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

बनाई गई Database देखना

बाद में INFORMATION_SCHEMA query करना या SHOW DATABASES चलाना confirm करता है कि आपकी नई database actually आपके intended character set और collation के साथ exist करती है, आपके इस पर tables बनाने से पहले typos पकड़ते हुए।

उदाहरण: Viewing the Created Database

sql
SHOW DATABASES;

⚠️ 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. CREATE DATABASE shop; दो बार चलाना, जो database exists के साथ fail हो जाता है जब तक आप IF NOT EXISTS add न करें।
  2. बाद में USE shop; चलाना भूल जाना, ताकि following CREATE TABLE गलत database में जाए या fail हो जाए।
  3. utf8mb4 के बिना एक database बनाना, ताकि emoji और कुछ characters पुराने setups में store न हो सकें।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 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.