今天用Mac安装mysql的时候,出现了各种问题:
- mysql无法启动
- mysql无法关闭
报的错误也很多,基本都是和pid相关的:
- ERROR! The server quit without updating PID file (/usr/local/mysql/data/tim.pid).
- ERROR! Multiple MySQL running but PID file could not be found (1007 2495 2582 )
- ERROR! MySQL server PID file could not be found!
- ERROR! MySQL is running but PID file could not be found
前前后后折腾了好久,也跟mysql的读写权限有关系,最后解决方式如下:
- sudo chmod -R 777 /usr/local/mysql/data // 获取data目录的访问权限
- rm -rf /usr/local/mysql/data //删除data目录
- mkdir /usr/local/mysql/data //新建一个data目录
- cd /usr/local
- sudo chown -R root:wheel mysql // 更改 mysql 安装目录所属用户与用户组
- cd /usr/local/mysql
- sudo bin/mysqld --initialize --user=mysql //切换到 mysql 安装目录并执行初始化命令并记录生成的临时 root 密码
挨个执行完以上命令后,会重新初始化mysql,拿到mysql的初始没密码,进行登录即可