MySQL
command line
Mac installation
SQL client
macOS

How do I install command line MySQL client on mac?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Installing the MySQL command-line client on macOS is a common requirement when you need to connect to managed databases or internal MySQL servers. The actual install step is quick, but many failures happen later from shell path issues, TLS settings, or authentication plugin mismatches. A reliable setup includes installation, path verification, secure credential handling, and connection validation.

Install the Client with Homebrew

For most developers, Homebrew is the simplest method.

bash
brew update
brew install mysql-client

This installs client tools such as mysql, mysqldump, and mysqladmin without starting a local MySQL server.

If Homebrew is not present, install it first from the official installer and then rerun the commands above.

Configure Shell Path Correctly

After installation, add the client binary path to your shell profile so the correct mysql executable is used.

Apple Silicon path:

bash
echo 'export PATH="/opt/homebrew/opt/mysql-client/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

Intel path:

bash
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

Verify:

bash
which mysql
mysql --version

If which mysql points to an old binary, fix path order before troubleshooting credentials.

Connect to a Database from CLI

Typical connection command:

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

After login, run a quick health check:

sql
SELECT VERSION();
SHOW DATABASES;

For environments that enforce encrypted transport, use explicit SSL mode:

bash
mysql --ssl-mode=REQUIRED -h db.example.com -P 3306 -u app_user -p app_db

This avoids silent fallback behavior and makes security intent clear.

Store Credentials Safely

Avoid passing password directly on command line. It can leak into history and process inspection tools.

Prefer login paths:

bash
1mysql_config_editor set \
2  --login-path=prod \
3  --host=db.example.com \
4  --user=app_user \
5  --password

Then connect with:

bash
mysql --login-path=prod app_db

This method is both safer and easier for repetitive use.

Common Troubleshooting Workflow

When connection fails, use a deterministic sequence:

  1. verify binary path and version
  2. check host and port reachability
  3. verify TLS requirements
  4. verify username and permissions
  5. confirm auth plugin compatibility

Basic network checks:

bash
nc -vz db.example.com 3306

If network is blocked, no client-side SQL command will succeed.

Handle Authentication Plugin Mismatch

Managed services and newer MySQL versions may use auth plugins that old clients do not support.

Inspect server version:

sql
SELECT VERSION();

Inspect client version:

bash
mysql --version

If you see plugin-related errors, upgrade client version and align with server authentication settings. Do not weaken authentication settings as a first fix.

Scripted Usage Pattern

For automation jobs, avoid interactive prompts by using login paths and explicit command flags.

bash
mysql --login-path=prod -e "SELECT NOW();"
mysqldump --login-path=prod app_db > backup.sql

In CI, inject secrets through secure environment tooling rather than hardcoding them in scripts.

Optional Alternative: Vendor Installer

Some teams prefer Oracle-provided packages instead of Homebrew. That is valid, but keep the same validation steps:

  • verify actual binary path
  • verify version
  • confirm TLS behavior
  • validate target server authentication

No matter how client is installed, operational checks remain the same.

Common Pitfalls

A common mistake is installing client correctly but never updating shell path. The terminal still uses an outdated binary and produces confusing errors.

Another issue is embedding passwords in command history for convenience. This is risky and avoidable.

TLS misconfiguration is also frequent. Production databases may reject non-encrypted sessions, so always test with explicit SSL mode.

Developers also skip version checks and spend time debugging what is actually an auth plugin mismatch.

Finally, local and CI environments often diverge in client versions. Pin versions and document setup so team behavior stays consistent.

Summary

  • Homebrew mysql-client is the fastest install path for macOS CLI usage.
  • Correct PATH setup is essential to ensure the expected binary is used.
  • Validate connectivity, TLS, and auth compatibility early.
  • Use mysql_config_editor login paths instead of plain-text password flags.
  • Standardize client versions across developer machines and automation pipelines.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.