使用homebrew一键安装相应的包,因为homebrew会检测最新的版本,所以下载的mysql版本是5.7.*版本
最近安装的时候最新版本更新到8.x版本,
关于homebrew的安装,链接
➜ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
搜索一下mysql版本:
brew search mysql
==> Formulae
automysqlbackup mysql-cluster mysql-search-replace mysql@5.7
mysql mysql-connector-c mysql-utilities mysqltuner
mysql++ mysql-connector-c++ mysql@5.5
mysql-client mysql-sandbox mysql@5.6
==> Casks
homebrew/cask/mysql-connector-python homebrew/cask/navicat-for-mysql
homebrew/cask/mysql-shell homebrew/cask/sqlpro-for-mysql
homebrew/cask/mysql-utilities
安装mysql:
➜ brew install mysql@5.7
➜ ln -sfv /usr/local/opt/mysql@5.7/*.plist ~/Library/LaunchAgents
➜ mysql.server start
如果mysql.server start
说zsh: command not found: mysql.server
的话,配置一下环境变量,如果是卸载重新切换版本的话brew link mysql@5.7
上面的第二步骤是设置开机启动
登录
➜ mysql -uroot
show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
修改root密码
use mysql
update user set authentication_string = password('root') where User='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
以前修改mysql密码字段是Password这个字段,但是mysql5.7没有这个字段而是使用了authentication_string替代
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
如果操作过程中报下面的错误
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
那么使用首先关闭mysql服务,然后以安全模式启动
mysql.server start --skip-grant-tables