When installing mysql-client
via Homebrew, you typically add the bin
directory to your PATH in .zprofile
or .zshrc
.
For example:
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:
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
.
Comments