Table of Contents
- Getting connected and oriented
- The query commands that do the real work
- Escaping to the shell and back
- Query attributes and session settings
- Reading output and knowing when something is off
- Mistakes that cost people time
- When to leave the command line
- A short procedure for a typical session
- MySQL Command Line FAQ[+]
The commands you actually use in the mysql client are a short list. They are connecting with mysql -u, running queries, checking status, escaping to the shell with system, and setting session attributes with query_attributes. Most of the rest of the client’s command set is documentation you read once and forget. This guide walks the ones that earn their place in daily work, with the versions where behaviour changed so you are not surprised mid-task.
Getting connected and oriented
The first command is the one you type in your own shell, before the mysql client even opens. On Linux, macOS, or Windows you connect with the mysql binary and a user flag.
“
mysql -u youruser -p -h localhost yourdatabase“
The -h flag names the host, and the trailing word is the database you want selected on login. Once you are in, the prompt changes and you are talking to the server, not your operating system. That distinction matters for everything below.
Inside the client, the first thing worth knowing is that every client command starts with a backslash or is a bare word like status. Queries end with a semicolon. If you type a query and hit Enter and nothing happens, you are missing the semicolon, and the client is waiting. Type \c to cancel the half-typed statement and start again.
The status command gives you a snapshot of the session. It reports the connection id, the current database, the server version, the character set, and the uptime. It also shows the current time. The client can present that in 24-hour military time (0–23) or standard 12-hour time depending on how the session is configured. That is a small thing, but when you are reading logs across time zones it saves a mental conversion.

The query commands that do the real work
Most of your time in the client is spent on four statement families. These are SELECT, INSERT, UPDATE, and DELETE. The client does not change how these work. It just gives you a place to type them and see the result grid.
A few client behaviours around queries are worth knowing. The \G terminator sends the same query but prints results vertically, one field per line. That is the difference between a readable row and a horizontal scroll on a wide table. Use it when a SELECT * spills off the screen.
The source command runs a SQL file from disk without leaving the client.
“ source /path/to/script.sql “
That is how you load a dump or replay a migration on a machine where you only have console access. It is also how you avoid pasting a hundred lines into a terminal that might mangle them.
The tee command starts logging everything the client prints to a file, and notee stops it. When you are debugging a query that returns something odd, turning on tee means you have the exact output to compare later. It is a small habit that pays off when a result looks different the second time you run it.
One warning that catches people: from MySQL 8.0.28, a client command used inside a transaction block raises a warning. If you are mid-transaction and reach for a client command, the client is telling you the session state is not what you think. Commit or roll back first.
Escaping to the shell and back
The system command runs an operating system command without leaving the mysql client:
“ system ls -la “
Before MySQL 8.0.19, that command worked only on Unix. From that release it also works on Windows. If you are on an older server and the command does nothing on a Windows box, that is why. On a current install it behaves the same on both.
This is the command that saves you from opening a second terminal just to check a file path or list a directory before you source a script. You run the shell command, see the output, and you are still at the mysql prompt.
The flip side is that system runs with the privileges of the user who started the client. On a shared machine, that is a reason to be careful about what you type. If you would not run it in a shell, do not run it through system.
Query attributes and session settings
The query_attributes command lets you attach name and value pairs to the queries you send. The client permits up to 32 attribute name/value pairs, and names and values may each be up to 1024 characters long. You set those attributes with a name and value pair.
You set them like this:
“ query_attributes mykey myvalue “
and clear them when you are done. The limits are generous for normal use but real. If you are building a workflow that stuffs metadata into attributes, count your pairs and keep names and values inside the length cap.
Session settings are the other half of this. SET statements change how the current session behaves, and they last until you disconnect. That is why a query that works in one terminal can fail in another. The session state is different, and nothing in the client tells you that unless you check.

Reading output and knowing when something is off
The client’s output is plain text. That is both its strength and its trap. Numbers come back as text in the grid, and a NULL looks different from an empty string only if you read carefully. When a result surprises you, check the column type before you trust the value.
The status command is your first diagnostic. It shows whether you are connected, which database is selected, and how long the session has been open. If you thought you were in one database and the status says another, you have your answer before you run a single query.
Warnings are the second diagnostic. A truncated value, deprecated syntax, or a transaction warning can appear after a statement. Reading them is the difference between a clean import and a silent data problem.
The help command inside the client lists the client commands and gives you the syntax for each. It is the reference you reach for when you forget whether a command takes an argument. It gives you the syntax for each client command.
Mistakes that cost people time
The most common mistake is running a DELETE or UPDATE without a WHERE clause and finding out after the fact. The client will happily execute it. There is no undo at the prompt.
The second is forgetting that client commands and SQL statements live in different namespaces. Typing status; with a semicolon sends it as SQL and you get a syntax error. Typing \s gets you the status. The backslash form and the bare word form are not always interchangeable, and the help output tells you which is which.
The third is assuming a command works the same across versions. The system command’s Windows support arrived in that same release. The ability to disable a client command arrived in 8.0.40 and later. If you are writing instructions for a team on mixed versions, check the version before you promise a behaviour.
The fourth is leaving tee running and wondering why the disk is filling. Logging is useful, but it is not free. Turn it off when you are done.

When to leave the command line
The command line is the right tool for scripted work, remote servers, and any task where you need to see exactly what the server returns. It is the wrong tool when you are exploring a schema you do not know, or when you need to compare result sets side by side.
For those jobs, a graphical client earns its place. The trade-off is that a GUI hides the session state that the console makes visible. A good habit is to learn the console commands first, then use the GUI as a convenience on top of that understanding.
If you are running the client on a server you reach over the network, the transport matters as much as the commands. Plain FTP sends credentials in the clear. If you are unsure which file transfer protocol you are actually using, this explainer on what FTP stands for in plain English is worth a read before you move SQL dumps around. For a comparison of the secure variants, see is FTP secure, plain FTP versus FTPS versus SFTP.
And if you are practising on cheap or free infrastructure, know what you are getting. A review of what free hosting really costs you covers the limits that show up once you start running real queries against a real database.
A short procedure for a typical session
Here is the sequence that covers most console work, from login to logout.
- Connect with
mysql -u youruser -p -h host databaseand confirm the prompt changed. - Run
statusto check the connection, the selected database, and the server version. - Set any session attributes you need with
query_attributes, keeping pairs and lengths within the client limits. - Run your queries, ending each with a semicolon, and use
\Gwhen a wide row needs vertical output. - Turn on
teeif you want a log of the session, andnoteewhen you are done. - Use
systemto check a file path before yousourcea script. - Read the warnings the client prints, then
exitto close the session cleanly.
That is the whole loop. The commands are few, and the discipline is in reading what the client tells you.
MySQL Command Line FAQ
How many query attributes can I set in one session?
The client permits up to 32 attribute name/value pairs. Each name and each value may be up to 1024 characters long, so the practical limit is usually set by your own metadata design.
Does the system command work on Windows?
Yes, from MySQL 8.0.19 onward. Before that version it worked only on Unix, so an older Windows install will not run shell commands through the client.
Can I disable a client command?
Yes, in MySQL 8.0.40 and later a client command can be disabled. That is useful on locked-down installs where you want to prevent shell access from inside the client.
Why did I get a warning about a transaction block?
From MySQL 8.0.28, a client command used inside a transaction block raises a warning. The client is telling you the session state may not match what you expect, so commit or roll back before continuing.
How do I see the current time in the client?
The status command reports the current time, and the client can show it in 24-hour military time (0–23) or standard 12-hour time depending on session configuration. Check the output rather than assuming a format.
Thank you for reading!

