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

MySQL Command Line

Opening the Command Line

The mysql command-line client connects directly to the server without any GUI overhead, which makes it the fastest option for quick checks, scripting, or working over SSH on a remote server with no graphical tools installed.

Example: Opening the Command Line

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

Executing Commands

Every statement at the prompt must end in a semicolon before MySQL will execute it — pressing Enter alone just starts a new line, which is why a forgotten semicolon leaves you stuck on a -> continuation prompt.

Example: Executing Commands

sql
SELECT 'Hello';

Navigating Databases

Running USE followed by a database name sets your active database for the session, so subsequent table references don't need to be fully qualified with the database name each time.

Example: 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.

Formatting Console Output

Built-in functions like CONCAT, UPPER, or ROUND can reshape values as they're displayed without altering the stored data, which is handy for making raw terminal output more readable during quick investigations.

Example: Formatting Console Output

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

Closing the Session

Typing EXIT or QUIT closes the client connection cleanly and frees the server-side resources tied to your session — leaving connections open unnecessarily can eventually exhaust a server's max-connection limit.

Example: Closing the Session

sql
-- Type EXIT; or QUIT; at the prompt to close the client connection
🔒

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.