Connecting to MySQL Using Command Line Options
Using host, port, username, password, and execution options with the mysql CLI client.
# 1. Basic local connection mysql -u root -p # 2. Connect to remote host & port mysql -h db.example.com -P 3306 -u dbuser -p company_db # 3. Run inline query without entering shell mysql -u root -p -e "SHOW TABLES FROM company_db;"
+----------------------+ | Tables_in_company_db | +----------------------+ | employees | | departments | +----------------------+