Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
MySQL + SQL · Lesson 33

MySQL Command Line (CLI) Basics

In this lesson: Log in to MySQL CLI and use essential commands — show, use, describe, source, exit — with output screenshots-style.

What is the MySQL CLI

The MySQL command line (CLI) is a text window where you type SQL commands and instantly see results. It has no buttons or menus — just you and the mysql> prompt. Learning a few core commands here makes you comfortable anywhere MySQL runs.

💡 The CLI is direct: type a command, end it with ;, press Enter, and see the result.

Logging in

mysql -u root -p
Enter password: ****** Welcome to the MySQL monitor. mysql>

-u root is the username and -p asks for the password. After the correct password, you reach the mysql> prompt, ready for commands.

SHOW commands

SHOW DATABASES;
+--------------------+ | Database | +--------------------+ | information_schema | | school | +--------------------+

SHOW DATABASES; lists every database on the server. After selecting one, SHOW TABLES; lists its tables. These help you see what exists.

USE and DESCRIBE

USE school;
DESCRIBE students;
+-------+-------------+------+-----+ | Field | Type | Null | Key | +-------+-------------+------+-----+ | roll | int | NO | PRI | | name | varchar(50) | YES | | | marks | int | YES | | +-------+-------------+------+-----+

USE selects a database; DESCRIBE (or DESC) shows a table's columns, types and keys — handy when you forget a table's layout.

Running a query

SELECT name, marks FROM students WHERE marks > 40;
+------+-------+ | name | marks | +------+-------+ | Aman | 88 | +------+-------+

You type a query, end it with ;, and press Enter. MySQL runs it and prints the result as a neat table right in the terminal.

Handy helpers

  • \c — cancel the command you are typing.
  • system clear (Linux/Mac) — clear the screen.
  • SELECT VERSION(); — show the MySQL version.
  • exit; or quit; — leave the MySQL CLI.

These small commands make working in the CLI smoother.

Common mistakes

  • Forgetting the semicolon. The command will not run until you add ;.
  • Wrong username or password. Check the -u value and the password.
  • Running queries before USE. Select a database first.
  • Typing exit without a semicolon. Most versions accept exit, but exit; is safest.

Summary

  • The MySQL CLI runs SQL commands directly at the mysql> prompt.
  • Log in with mysql -u root -p.
  • SHOW DATABASES/SHOW TABLES list what exists.
  • USE selects a database; DESCRIBE shows a table's columns.
  • End commands with ; and quit with exit;.

Next, build your first data with MySQL first commands, or use a visual tool in MySQL Workbench.

Frequently Asked Questions

What is the MySQL command line (CLI)?
The MySQL CLI is a text interface where you type SQL commands and see results directly. You log in with your username and password, then run queries like SHOW DATABASES or SELECT. It is the most direct way to work with MySQL.
How do I log in to MySQL from the command line?
Type mysql -u root -p and press Enter, then type your password. -u is the username and -p prompts for the password. On success you get the mysql> prompt.
How do I list all databases and tables?
Use SHOW DATABASES; to list databases, then USE dbname; to select one, and SHOW TABLES; to list its tables. DESCRIBE tablename; shows a table's columns.
How do I exit the MySQL command line?
Type exit; or quit; and press Enter. Both close the MySQL session and return you to the normal terminal.
What does DESCRIBE do in MySQL?
DESCRIBE tablename; (or DESC) shows the structure of a table — its columns, their data types, whether they allow null, and which is the key. It is useful to remember a table's layout.
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 Live Code Editor

This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.
Next topicSQL Commands: DDL, DML, DQL, DCL and TCL Your progress: 33 / 151 (22%) · Lesson 34 / 151 Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free