MySQL Command Line
In this page:
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
-- 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
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
USE test_db;
SELECT * FROM users;
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
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
-- 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: