Mac os安装MySQL数据库,系统提示mysql: command not found该怎么办 - 随风飘-挨刀刀 - 博客园 适用 brew install mysql 之后

关联文章
mac 通过brew 安装的mysql启动失败解决方案_weixin_33681778的博客-CSDN博客

当我们安装好MySQL后,在终端输入mysql命令,发现并不能看到自己安装的数据库,这是因为你没有配置环境变量。

在os系统中安装MySQL数据库默认保存在/usr/local/mysql

那么我们应该如何配置环境变量呢?

1、打开terminal,输入:sudo su   回车  进入系统管理员管理目录(当然你要输入你的用户密码才能进入)

2、输入命令:vim /etc/profile   接着就进入到vim编辑界面

3、在vim编辑界面,按i进入编辑状态,接着,就可以增加路径名称,输入命令:

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

修正 本机安装了oh-my-zsh

# php
#export PATH="$(brew --prefix /Cellar/php/7.4.11)/bin:$PATH"
# export PATH="/usr/local/Cellar/php/7.4.11/bin:$PATH"
export PATH="$(brew --prefix php@7.4)/bin:$PATH"

# maven
# export PATH="/usr/local/opt/maven@3.2/bin:$PATH"
export PATH="$(brew --prefix maven@3.2)/bin:$PATH"

# mysql echo "$(brew --prefix mysql@5.7)"
export PATH="$(brew --prefix mysql@5.7)/bin:$PATH"

生效

source ~/.zshrc

mysql 初始化

➜  5.7.31 mysql_install_db --verbose --user=root --basedir="$(brew --prefix mysql)"--datadir=/Users/linjinyu/MYSQL_HOME/data --tmpdir=/tmp
mysql_install_db: [ERROR] unknown variable 'tmpdir=/tmp'
2020-10-22 10:23:12 [ERROR]   Unrecognized options
➜  5.7.31 mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Please set the password for root here.

New password: 

Re-enter new password: 

Estimated strength of the password: 50 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 

4、按下esc键,退出编辑状态

5、输入命令: :wq!  (表示保存并强制退出)

6、接着就调回我之前的那个terminal界面了:

7、在这个界面接着输入命令:source /etc/profile   表示设置立即生效,当然你关闭后重启也是一样的道理

这时可以输入:mysql  回车 进行测试

如果系统还是提示 mysql: command not found怎么办?

1、苹果 -> 系统偏好设置 -> 最下边点mysql  在弹出页面中  关闭mysql服务;

2、进入终端输入:cd /usr/local/mysql/bin

3、回车后 登录管理员权限 sudo su  (输入你电脑的密码)

4、回车后输入以下命令来禁止mysql验证功能  ./mysqld_safe --skip-grant-tables &    (注意是mysqld)

5、回车后mysql会自动重启(偏好设置中可以看到mysql的状态会变成running)

6、接着输入命令 ./mysql

7、回车后可以看到如下效果:

出现了让人舒心的 mysql> 提示符!!!

8、下面就是修改密码

接着输入:FLUSH PRIVILEGES;

回车后,输入:SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123');

9、重新打开一个terminal,输入:mysql -uroot -p123  即可进入MySQL数据了:

参考:https://blog.csdn.net/adley_app/article/details/54694230


原网址: 访问
创建于: 2020-10-22 10:04:24
目录: default
标签: 无

请先后发表评论
  • 最新评论
  • 总共0条评论