最近因为要配置laravel,所以用 brew 的方式安装了mysql5.7
当时的命令是
$ brew install mysql@5.7
安装完成后,初始化mysql
$ mysqld --initialize --user=root --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql
然后没有记得当时给出的mysql的密码,所以想要去修改mysql的root密码,结果始终无法终止mysql,kill之后又会重新启动
然后到网上找,有以下几个方案:
1、在“系统偏好设置”中,找到mysql,点击停止。我看了我的,没有mysql
2、应该是有守护进程在保护mysql,所以kill后,就立即重启了。发现我的就是这个问题,然后按照网上的方法到相应的目录下去找,结果找不到。
我开始回顾之前的安装过程,因为是用brew安装的,那么是不是应该用brew的方式来停止呢,找到了命令
$ brew services stop mysql
Error: Service `mysql` is not started.
然后我就晕了,怎么办
终极解决方案
我开始查找以前的命令,如下:
$ history| grep brew
125 brew install mysql@5.7
138 mysqld --initialize --user=root --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql
140 brew services start mysql@5.7
终于发现了,名称不是 mysql,而是 mysql@5.7
$ brew services stop mysql@5.7
Stopping `mysql@5.7`... (might take a while)
==> Successfully stopped `mysql@5.7` (label: homebrew.mxcl.mysql@5.7)
finally,终于能停止了。
然后删除之前的数据库,因为我的数据库没有任何数据
$ rm -rf /usr/local/var/mysql
重新初始化数据库
$ mysqld --initialize --user=root --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql
2018-11-08T11:18:38.363097Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-08T11:18:38.363429Z 0 [ERROR] Can't find error-message file '/usr/local/Cellar/mysql/8.0.12/share/mysql/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2018-11-08T11:18:38.364686Z 0 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2018-11-08T11:18:38.365951Z 0 [Warning] One can only use the --user switch if running as root
2018-11-08T11:18:38.623185Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-11-08T11:18:38.669267Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-11-08T11:18:38.738631Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 0a74ee2c-e348-11e8-9910-9e9202539a0c.
2018-11-08T11:18:38.759261Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-11-08T11:18:39.084092Z 0 [Warning] CA certificate ca.pem is self signed.
2018-11-08T11:18:39.270413Z 1 [Note] A temporary password is generated for root@localhost: vdCgrtgX+I6os
在最后一行 generated for root@localhost: vdCgrtgX+I6os,记下数据库密码,然后重新启动mysql
$ brew services start mysql@5.7
==> Successfully started `mysql@5.7` (label: homebrew.mxcl.mysql@5.7)
终于搞定了。