用 brew 将 mysql 从5.6.22升级到了5.7, 启动mysql服务以后发现登录不进去, 原来的密码失效, 应该是两个版本的 mysql.user表结构的差异造成的, 为了保留之前的数据, 所以卸载了5.7.x. 卸载以让命令后重新指向5.6.22, 用mysql.server命令启动mysql, 这个时候报错了,启动不了:
. ERROR! The server quit without updating PID file (/usr/local/var/mysql/xxx.local.pid). 此处的 xxx是我电脑的名字,下同
这个时候先不要去搜索引擎搜索以上的错误提示,不然会找到很多不同的无效的解决方案,要定位问题还是先查看日志,避免做无用功. 我刚开始就是这么做的,浪费了不少时间.
查看日志/usr/local/var/mysql/xxx.local.err, 发现以下问题:
2016-08-03 18:18:59 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-08-03 18:18:59 81707 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
2016-08-03 18:18:59 81707 [Note] Plugin 'FEDERATED' is disabled.
2016-08-03 18:18:59 81707 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-08-03 18:18:59 81707 [Note] InnoDB: The InnoDB memory heap is disabled
2016-08-03 18:18:59 81707 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-08-03 18:18:59 81707 [Note] InnoDB: Memory barrier is not used
2016-08-03 18:18:59 81707 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-08-03 18:18:59 81707 [Note] InnoDB: Using CPU crc32 instructions
2016-08-03 18:18:59 81707 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-08-03 18:18:59 81707 [Note] InnoDB: Completed initialization of buffer pool
2016-08-03 18:18:59 81707 [Note] InnoDB: Highest supported file format is Barracuda.
InnoDB: No valid checkpoint found.
InnoDB: If this error appears when you are creating an InnoDB database,
InnoDB: the problem may be that during an earlier attempt you managed
InnoDB: to create the InnoDB data files, but log file creation failed.
InnoDB: If that is the case, please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.6/en/error-creating-innodb.html
2016-08-03 18:18:59 81707 [ERROR] Plugin 'InnoDB' init function returned error.
2016-08-03 18:18:59 81707 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2016-08-03 18:18:59 81707 [ERROR] Unknown/unsupported storage engine: InnoDB
2016-08-03 18:18:59 81707 [ERROR] Aborting
重点在:
InnoDB: to create the InnoDB data files, but log file creation failed.
通过这个关键点 google 了一下, 找到解决方法:
删除ib_logfile0和ib_logfile1这两个文件,不过最好是重命名这两个文件,就算此方案无效, 还有补救的机会. 接着再启动mysql服务器, ok 了.