Homebrew简称brew,OSX上的软件包管理工具,在Mac终端能够经过brew安装、更新、卸载各类软件,(简直就是神器级武器)。mysql
废话很少说,没安装brew本身去百度学习安装,这里就很少说了。sql
brew search mysql
brew install mysql@5.7
MySQL is configured to only allow connections from localhost by default To connect run: mysql -uroot mysql@5.7 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 mysql@5.7 first in your PATH run: echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile For compilers to find mysql@5.7 you may need to set: export LDFLAGS="-L/usr/local/opt/mysql@5.7/lib" export CPPFLAGS="-I/usr/local/opt/mysql@5.7/include" To have launchd start mysql@5.7 now and restart at login: brew services start mysql@5.7 Or, if you don't want/need a background service you can just run: /usr/local/opt/mysql@5.7/bin/mysql.server start ==> Summary 🍺 /usr/local/Cellar/mysql@5.7/5.7.23: 317 files, 234.1MB
以上信息需注意系统环境变量的配置:bash
echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile # 文件修改之后执行写入bash_profile之后执行当即生效 sousers ~/.bash_profile
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 显示以下ui
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 显示以下this
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显示以下rest
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';code
成功 Query OK, 1 row affected, 1 warning (0.05 sec) Rows matched: 1 Changed: 1 Warnings: 1
到这来就完成啦。
最后从新登终端输入:
mysql -u root -p
按回车键,输入设置的密码便可登陆orm
以上所述给你们介绍的解决mac使用homebrew安装MySQL,并出现没法登录问题的解决方案,但愿对你们有所帮助。