Icon

Littleor

234 分类: 闲语

【环境踩坑】Mac通过HomeBrew下安装Mysql无法启动的原因

前言

在Mac版本: 12.2.1 下希望能装个Mysql8 (8.0.28),结果安装的时候报错:

2022-03-13T07:59:03.687991Z 0 [ERROR] [MY-000077] [Server] /usr/local/Cellar/mysql/8.0.28_1/bin/mysqld: Error while setting value 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' to 'sql_mode'.
2022-03-13T08:10:34.238494Z 0 [System] [MY-013169] [Server] /usr/local/Cellar/mysql/8.0.28_1/bin/mysqld (mysqld 8.0.28) initializing of server in progress as process 28833
2022-03-13T08:10:34.245359Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2022-03-13T08:10:34.245368Z 0 [ERROR] [MY-013236] [Server] The designated data directory /usr/local/var/mysql/ is unusable. You can remove all files that the server added to it.
2022-03-13T08:10:34.245442Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-03-13T08:10:34.249426Z 0 [System] [MY-010910] [Server] /usr/local/Cellar/mysql/8.0.28_1/bin/mysqld: Shutdown complete (mysqld 8.0.28)  Homebrew.
Warning: The post-install step did not complete successfully

直接启动也无法连接

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

错误信息

分析

定位错误信息:

Error while setting value 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' to 'sql_mode'.

明显是 Mysql 问题,需要手动设置 sql_mode ,那么通过 homebrew 安装的 Mysql 配置文件在哪呢?

/usr/local/etc/my.cnf

所以只需要修改下这个文件里面的 sql_mode 即可:

去除掉 NO_AUTO_CREATE_USER 即可

sql_mode ="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"

删除 NO_AUTO_CREATE_USER 完成之后执行下面的指令来重新初始化 Mysql 即可

rm -rf /usr/local/var/mysq
brew postinstall mysql       

最后启动服务

brew services restart mysql

连接 Mysql

mysql -uroot

#none

作者: Littleor

版权: 除特别声明,均采用BY-NC-SA 4.0许可协议,转载请表明出处

目录Content

评论