Homebrew(brew)安装MySQL成功后无法登录

Posted Mr.huang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Homebrew(brew)安装MySQL成功后无法登录相关的知识,希望对你有一定的参考价值。

Homebrew简称brew,OSX上的软件包管理工具,在Mac终端可以通过brew安装、更新、卸载各种软件,(简直就是神器级武器)。

废话不多说,没安装brew自己去百度学习安装,这里就不多说了。

1、首先在终端使用命令,这是搜索brew上的mysql各个版本
brew search mysql
2、选择自己需要的版本,安装MySQL,这里我安装为5.7版本
brew install [email protected]
3、执行后稍等片刻,它会自动安装,以下为安装成功后显示的信息
MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

[email protected] is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have [email protected] first in your PATH run:
  echo ‘export PATH="/usr/local/opt/[email protected]/bin:$PATH"‘ >> ~/.bash_profile

For compilers to find [email protected] you may need to set:
  export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
  export CPPFLAGS="-I/usr/local/opt/[email protected]/include"


To have launchd start [email protected] now and restart at login:
  brew services start [email protected]
Or, if you don‘t want/need a background service you can just run:
  /usr/local/opt/[email protected]/bin/mysql.server start
==> Summary
??  /usr/local/Cellar/[email protected]/5.7.23: 317 files, 234.1MB

以上信息需注意系统环境变量的配置:

echo ‘export PATH="/usr/local/opt/[email protected]/bin:$PATH"‘ >> ~/.bash_profile

# 文件修改以后执行写入bash_profile以后执行立即生效
sousers ~/.bash_profile
4、最后执行,启动MySQL
mysql.server start

# 显示如下,则安装成功
Starting MySQL
. SUCCESS! 

附加:

终端输入

mysql -u root

如果你运气不好,出现如下错误,应该是修改初始密码没有成功

ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES),
解决步骤

(1)终端输入 mysqld_safe --skip-grant-tables 显示如下

mysqld_safe --skip-grant-tables

# 显示如下
2017-03-21T11:44:11.6NZ mysqld_safe Logging to ‘/usr/local/var/mysql/huang.local.err‘.
2017-03-21T11:44:11.6NZ mysqld_safe Logging to ‘/usr/local/var/mysql/huang.local.err‘.
2017-03-21T11:44:11.6NZ mysqld_safe A mysqld process already exists

(2)再次输入 mysql -u root 显示如下

Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 10
Server version: 5.7.17 Homebrew
Copyright (c) 2000, 2016, 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>

(3)终端输入 use mysql显示如下

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql>

(4)修改密码 UPDATE mysql.user SET authentication_string=PASSWORD(‘你的密码‘) WHERE User=‘root‘;

成功  Query OK, 1 row affected, 1 warning (0.05 sec)
Rows matched: 1  Changed: 1  Warnings: 1

到这来就完成啦。
最后重新登终端输入:
mysql -u root -p
按回车键,输入设置的密码即可登录

以上所述给大家介绍的解决mac使用homebrew安装MySQL,并出现无法登陆问题的解决方案,希望对大家有所帮助。




以上是关于Homebrew(brew)安装MySQL成功后无法登录的主要内容,如果未能解决你的问题,请参考以下文章

Homebrew 安装mysql

mac brew 怎么安装msql 5.5

macOS使用brew安装mysql8.x

mac安装homebrew失败怎么办

Mac M1开发环境的安装与配置(Homebrew)

安装homebrew