mac安装mysql,并配置环境变量后,重新打开终端无法直接mysql-uroot -p进入mysql
问题:
根据网上安装教程配置了mysql后,配置了.bash_profile全局变量,关掉终端发现重新打开终端输入mysql -uroot -p
报错找不到。但是输入:/usr/local/mysql/bin/mysql -u root -p
,可以正常进入mysql。
思考:说明mysql安装没有问题,但是全局配置可能出了问题。
解决办法:
1.先查看mac本身安装的shell有哪些?
cat /etc/shells
结果:
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.
/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
以上显示内容都为本机已安装的shell
2.查看默认shell
chsh
回车之后,会让输入本机启动密码,开机密码,输入完成后可以看见如下,结果:
# Changing user information for iOSTeam.
# Use "passwd" to change the password.
##
# Open Directory: /Local/Default
##
Shell: /bin/zsh
Full Name: iOSTeam
Office Location:
Office Phone:
Home Phone:
~
如上所示,默认shell为zsh,说明安装mysql时部署的全局变量bash的效用没生效。
3.需要配置的为vi ~/.zshrc
,进入后输入如下:
export PATH=${PATH}:/usr/local/mysql/bin
保存退出后,source ~/.zshrc
4.退出终端,重新打开后输入mysql -uroot -p
,发现成功进入mysql。
如上,问题解决。