Mac安装mysql后无法使用命令行zsh: command not found: mysql

Mac安装mysql后无法使用命令行zsh: command not found: mysql

liangyuji@liangyujideMacBook-Pro ~ % mysql

zsh: command not found: mysql

原因:没有配置环境变量

1. 在/etc/profile配置环境变量

再下面新增配置路径(测试发现临时有效)

export PATH=$PATH:/usr/local/mysql/bin

Mac安装mysql后无法使用命令行zsh: command not found: mysql_第1张图片

添加路径

liangyuji@liangyujideMacBook-Pro ~ % sudo vim /etc/profile
Password:
liangyuji@liangyujideMacBook-Pro ~ % mysql
zsh: command not found: mysql
liangyuji@liangyujideMacBook-Pro ~ % source /etc/profile

更新配置,立即生效

$ source /etc/profile
liangyuji@liangyujideMacBook-Pro ~ % mysql
ERROR 1045 (28000): Access denied for user 'liangyuji'@'localhost' (using password: NO)

这时发现已经可以看到mysql可以使用了

注意⚠️:但重新打开终端会发现失效了,要重新更新 $ source /etc/profile才行

liangyuji@liangyujideMacBook-Pro ~ % mysql
zsh: command not found: mysql
2.在/usr/local/bin配置:

1、在终端进入目录:/usr/local/bin

cd /usr/local/bin/

2、设置mysql命令路径

sudo ln -fs /usr/local/mysql/bin/mysql mysql

测试:

liangyuji@liangyujideMacBook-Pro ~ % mysql
zsh: command not found: mysql
liangyuji@liangyujideMacBook-Pro ~ % cd /usr/local/bin/
liangyuji@liangyujideMacBook-Pro bin % sudo ln -fs /usr/local/mysql/bin/mysql mysql
Password:
liangyuji@liangyujideMacBook-Pro bin % mysql 
ERROR 1045 (28000): Access denied for user 'liangyuji'@'localhost' (using password: NO)

关闭再重新打开,没有问题

liangyuji@liangyujideMacBook-Pro ~ % mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.22 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

你可能感兴趣的:(mysql,mysql,mac)