---
slug: "how-to-add-path-mysql-cient-bin-any-version"
title: "When Setting the Path for mysql-client Installed via Homebrew on macOS, It Automatically Follows Version Changes"
description: "Glossary of real-time pub/sub protocols (MQTT/STOMP/Redis Pub-Sub) and a comparison of Python clients to connect to each."
url: "https://www.ytyng.com/en/blog/how-to-add-path-mysql-cient-bin-any-version"
publish_date: "2023-01-25T00:13:12Z"
created: "2023-01-25T00:13:12Z"
updated: "2026-05-11T13:21:41.961Z"
categories: ["Shellscript(Bash/Zsh)"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20250708/3061ea959af443e1bbcb72f488294a88.png.webp?width=768"
has_video: false
has_music: false
video_urls: []
music_urls: []
lang: "en"
---

# When Setting the Path for mysql-client Installed via Homebrew on macOS, It Automatically Follows Version Changes

When installing `mysql-client` via Homebrew, you typically add the `bin` directory to your PATH in `.zprofile` or `.zshrc`.

For example:

```bash
if [ -d /usr/local/Cellar/mysql-client/8.0.22/bin ]; then
  export PATH=/usr/local/Cellar/mysql-client/8.0.22/bin:${PATH}
fi
```

However, this approach doesn't handle version changes well. To make the PATH setting adaptable to any version, you can use the following script:

```bash
for dir_name in $(ls -1 -r '/usr/local/Cellar/mysql-client'); do
    _path="/usr/local/Cellar/mysql-client/${dir_name}/bin"
    if [ -d "${_path}" ]; then
        export PATH=${_path}:${PATH}
        break
    fi
done

for dir_name in $(ls -1 -r '/usr/local/Cellar/mysql-client'); do
    _path="opt/homebrew/Cellar/mysql-client/${dir_name}/bin"
    if [ -d "${_path}" ]; then
        export PATH=${_path}:${PATH}
        break
    fi
done
```

This script iterates through the directories in `/usr/local/Cellar/mysql-client` and `/opt/homebrew/Cellar/mysql-client`, adding the first valid `bin` directory it finds to the PATH. This way, your PATH will automatically adjust to the installed version of `mysql-client`.
