mysql -u root -pPrompts for the password and connects using the default local socket or TCP settings.
mysql client commands for connecting, switching databases, inspecting metadata, and working efficiently in interactive or scripted sessions.
Connect, select a database, inspect metadata, and run SQL from the MySQL command line client.
mysql -u root -pPrompts for the password and connects using the default local socket or TCP settings.
Specify the host, port, user, and prompt for a password.
mysql -h db.example.com -P 3306 -u app_user -pUseful for connecting to staging, production, or containerized MySQL instances.
Open mysql and select the target schema immediately.
mysql -u app_user -p app_dbEquivalent to connecting first and then running `USE app_db;`.
mysql -u app_user -p -e "SHOW DATABASES;"Good for scripts, quick checks, and automation tasks.
SHOW DATABASES;Visibility depends on privileges.
USE app_db;After `USE`, unqualified table names resolve inside that schema.
SHOW TABLES;A quick way to inspect schema contents from the CLI.
Inspect columns, types, nullability, keys, and defaults.
DESCRIBE users;`DESC users;` is a common shorthand.
Display table DDL including indexes and engine options.
SHOW CREATE TABLE users\GUsing `\G` in the mysql client prints vertical output, which is easier to read for long DDL.
Inspect truncation, coercion, and non-fatal issues.
SHOW WARNINGS;Very useful after bulk imports or `INSERT ... SELECT` statements.
Useful flags and metadata commands for shell scripts and automation.
mysql -u app_user -p -N -e "SELECT id, email FROM users LIMIT 5;" app_db`-N` removes column names from the output.
Reduce formatting for machine-friendly results.
mysql -u app_user -p -B -e "SELECT NOW();"`-B` outputs tab-separated rows that are easier to parse in shell tools.
Write statements and output to a transcript file.
tee /tmp/mysql-session.logInside the mysql client, `tee` starts recording output; `notee` turns it off.
Display host, connection id, server version, and current database.
statusUseful for verifying where you are connected before running risky statements.
Inspect current client connections and statements.
SHOW PROCESSLIST;Helpful when diagnosing blocked queries or long-running sessions.
KILL 12345;Use carefully in production; get the connection id from `SHOW PROCESSLIST`.