MySQL Client and Connection Cheatsheet/Connect to a remote host and port

Specify the host, port, user, and prompt for a password.

Section: mysql client basics

Connect to a remote host and port

bash
bash
mysql -h db.example.com -P 3306 -u app_user -p
Explanation

Useful for connecting to staging, production, or containerized MySQL instances.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing mysql client basics
Connect to a local MySQL server
Open an interactive mysql session.
OpenIn sheetbashsame section
Connect directly to a database
Open mysql and select the target schema immediately.
OpenIn sheetbashsame section
Run one query and exit
Execute a SQL statement non-interactively.
OpenIn sheetbashsame section
List databases
Display all databases visible to the current account.
OpenIn sheetsqlsame section
Select a database
Set the active database for subsequent statements.
OpenIn sheetsqlsame section
List tables in the current database
Display tables in the selected schema.
OpenIn sheetsqlsame section