← Back to MySQL Course | Chapter 1: Introduction & Basics | Lesson 6 of 8

MySQL Command Line

MySQL command line database को सीधे text करने जैसा है। कोई buttons नहीं हैं, बस आप एक command type करते हैं और तुरंत जवाब पाते हैं।
Syntax
sql
mysql -u username -p
USE database_name;
SHOW TABLES;
statement;

Command Line खोलना

mysql command-line client बिना किसी GUI overhead के सीधे server से connect होता है, जो इसे quick checks, scripting, या बिना graphical tools installed किसी remote server पर SSH से काम करने के लिए सबसे तेज़ option बनाता है।

उदाहरण: Opening the Command Line

sql
-- mysql -u root -p    (run from a terminal to open the client)
SELECT 1;

Commands Execute करना

MySQL इसे execute करे उससे पहले prompt पर हर statement एक semicolon से खत्म होना ज़रूरी है — सिर्फ Enter दबाना एक नई line शुरू कर देता है, यही वजह है कि एक भूला हुआ semicolon आपको एक -> continuation prompt पर फँसा देता है।

उदाहरण: Executing Commands

sql
SELECT 'Hello';

Databases में Navigate करना

एक database name के बाद USE चलाना session के लिए आपकी active database set करता है, इसलिए बाद के table references को हर बार database name से fully qualified होने की ज़रूरत नहीं।

उदाहरण: Navigating Databases

sql
USE test_db;
SELECT * FROM users;

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

Console Output Format करना

CONCAT, UPPER, या ROUND जैसे built-in functions stored data बदले बिना display होते समय values को reshape कर सकते हैं, जो quick investigations के दौरान raw terminal output को ज़्यादा readable बनाने के लिए handy है।

उदाहरण: Formatting Console Output

sql
SELECT CONCAT(UPPER(name), ' - ', ROUND(salary, 0)) AS summary FROM employees;

Session बंद करना

EXIT या QUIT type करना client connection को cleanly बंद कर देता है और आपके session से जुड़े server-side resources free कर देता है — connections को unnecessarily खुला छोड़ना आख़िरकार एक server की max-connection limit खत्म कर सकता है।

उदाहरण: Closing the Session

sql
-- Type EXIT; or QUIT; at the prompt to close the client connection
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. किसी statement के अंत में ; भूल जाना, ताकि prompt -> में बदल जाए और कुछ न चले।
  2. command line पर सीधे password के साथ mysql -uroot -p लिखना, जो इसे shell history में expose कर देता है।
  3. पहले USE के बिना queries चलाना, ताकि आपको No database selected मिले।
🔒

Chapter Quiz — Complete all 8 topics to unlock

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