Complete Guide to Installing MySQL Command Line Client on macOS

Nov 22, 2025 · Programming · 11 views · 7.8

Keywords: MySQL | macOS | Command Line Client | Environment Variable Configuration | Homebrew

Abstract: This article provides a comprehensive guide to installing MySQL command line client on macOS systems, focusing on the best practice of installing through MySQL Workbench while comparing alternative methods using Homebrew and official DMG packages. It delves into technical details such as environment variable configuration and PATH setup, offering complete operational procedures and troubleshooting advice to help developers quickly set up MySQL development environments.

Introduction

In macOS development environments, the MySQL command line client serves as an essential tool for database management and development. Many developers often face confusion when initially attempting to install only the command line client rather than the complete MySQL server. Based on community practices and official documentation, this article provides detailed guidance on multiple installation methods.

Installing Command Line Client via MySQL Workbench

MySQL Workbench not only offers a graphical interface but also includes a complete set of command line tools. This is the most recommended installation method as it ensures tool version compatibility and stability.

First, download MySQL Workbench from the official MySQL website:

Visit https://dev.mysql.com/downloads/workbench/ to download the macOS version

After installation, you need to add the command line tools from Workbench to the system PATH:

export PATH=$PATH:/Applications/MySQLWorkbench.app/Contents/MacOS

This command temporarily adds the MySQL command line tool path to the current session's PATH environment variable. For permanent effect, it's recommended to add the above command to your shell configuration file.

Installing Standalone Client Using Homebrew

For developers who prefer package manager installations, Homebrew provides a more lightweight solution.

If Homebrew is not already installed, first execute the installation command:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Then install the mysql-client package:

brew install mysql-client

After installation, environment variable configuration is required:

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

Path Configuration for Existing MySQL Installation

If MySQL has already been installed on the system via DMG, you can utilize the existing command line tools by configuring the PATH.

Add the MySQL binary directory to PATH:

echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile
. ~/.bash_profile

After configuration, you can use the mysql command to connect to servers:

mysql -h server_address -u username -p

Detailed Environment Variable Configuration

Proper configuration of the PATH environment variable is crucial for using command line tools. In macOS, common shell configuration files include:

After configuration, you need to reload the configuration file using the source command or restart the terminal session.

Verifying Installation

After installation completion, verify whether the MySQL client is available using the following command:

mysql --version

If MySQL version information is displayed, the installation is successful. If the command is not found, check whether the PATH configuration is correct.

Troubleshooting

Common issues and solutions:

Conclusion

This article has introduced multiple methods for installing the MySQL command line client on macOS. Installation through MySQL Workbench provides the most complete toolset, while Homebrew installation offers a more lightweight approach. Regardless of the chosen method, proper environment variable configuration remains key to successful usage. Developers can select the most suitable installation approach based on their specific needs and preferences.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.