macos 将 mysql 加入环境变量

今天在mac上安装 mysql 安装完成后发现 mysql 命令并没有加入系统环境变量
手动添加步骤:

  1. 在~目录下新建 .bash_profile
$ touch .bash_profile
$ open -a TextEdit -e .bash_profile
  1. 打开 .bash_profile 文件输入命令并保存
$ export PATH=${PATH}:/usr/local/mysql/bin
  1. 重新加载 .bash_profile 文件
$ source  ~/.bash_profile
  1. 再使用 mysql 命令发现mysql命令已经生效

上面的方法有个问题,重新登陆就不好使了
将 mysql 写入系统文件

  1. 打开 /etc/profile 文件
$ sudo vim /etc/profile
  1. 在文件末尾将命令写入环境变量
$ export PATH=$PATH:/usr/local/mysql/bin
  1. 重新加载文件
$ source /etc/profile

还有些问题 macos 默认是 zsh

# 查看有没有 .zshrc 文件
$ ls -a | grep .zshrc
# 没有复制一份 .bash_profile 有就在最后加上.bash_profile的代码
$ cp ~/.bash_profile ~/.zshrc
$ source ~/.zshrc # 或重启
posted @ 2023-02-13 10:37  脉望  阅读(70)  评论(0编辑  收藏  举报