mac下用brew安装mysql后无法kill

本文记录了通过Brew安装MySQL5.7后遇到的启动与密码重置难题,详细描述了如何正确使用Brew服务命令来管理MySQL,以及重置root密码的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近因为要配置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)

终于搞定了。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值