600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > brew 安装mysql5.6_mac使用brew安装mysql的坑

brew 安装mysql5.6_mac使用brew安装mysql的坑

时间:2019-10-02 10:56:40

相关推荐

brew 安装mysql5.6_mac使用brew安装mysql的坑

## 记录一次Mac上用brew安装mysql遇到的坑 ##

brew安装mysql的步骤:

brew search mysql 查看远程仓库中有哪些mysql的版本

选择一个合适的mysql版本然后安装它, brew install mysql

安装好后,启动mysql,如果不知道怎么启动mysql,可以使用命令查看提示,brew info mysql,根据提示,有两种启动方式:brew services start mysql,或者 mysql.server start。

如果你使用brew services start mysql,会提示你没有brew 没有services命令,根据官网回复,发现这个命令从就从brew的命令中移除了,原因是services的开源作者已经不再维护这个命令了,原文解释链接。说实话,这个命令还是很好用的,只要记住软件的名字,就能管理软件的启动、关闭,只可惜原作者不再维护仓库了。

直接使用 mysql.server start 启动mysql,会发现报错了。

Starting MySQL

.. ERROR! The server quit without updating PID file (/usr/local/var/mysql/data/lingdeMacBook-Pro.local.pid).

然后网上一查这个报错,清一色的回答就是这种答案列举多种存在的原因,然后一试,全部方案发现都不行,还浪费时间。因为对mysql客户端的安装也没经验,病急乱投医,一股脑子谷歌查解决方案。网上那种列举多种存在原因的方式,不是说不好,但至少先科普一下有哪些标志性的症状导致的这种原因吧,不然像我们这种新手只能挨个试了。更可恶的是,全试之后,发现都无效,冷静之后,突然想起自己也是个程序员啊,程序启动不了出bug了,不会看日志吗?

mysql日志文件在哪?在上面报错提示中有写:/usr/local/var/mysql/data/,进入该文件夹中,会看到有个文件是 .err 文件,我的是lingdeMacBook-Pro.local.err。

查看日志文件,cat lingdeMacBook-Pro.local.err,找到报错的地方,如下

-04-19T15:32:03.348611Z 0 [Note] InnoDB: 5.7.29 started; log sequence number 0

-04-19T15:32:03.361731Z 0 [Note] Plugin 'FEDERATED' is disabled.

mysqld: Table 'mysql.plugin' doesn't exist

-04-19T15:32:03.397132Z 0 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.

-04-19T15:32:03.457609Z 0 [ERROR] unknown variable 'mysqlx-bind-address=127.0.0.1'

-04-19T15:32:03.457784Z 0 [ERROR] Aborting

看到具体的报错就好办了,日志提示我使用mysql_upgrade更新mysql版本,以为终于能搞定了,按耐不住的心情赶紧照做,然而我还是太年轻了。

mysql_upgrade --protocol=tcp -P3306 -p,提示如下

The mysql_upgrade client is now deprecated. The actions executed by the upgrade client are now done by the server.

To upgrade, please start the new MySQL binary with the older data directory. Repairing user tables is done automatically. Restart is not required after upgrade.

The upgrade process automatically starts on running a new MySQL binary with an older data directory. To avoid accidental upgrades, please use the --upgrade=NONE option with the MySQL binary. The option --upgrade=FORCE is also provided to run the server upgrade sequence on demand.

It may be possible that the server upgrade fails due to a number of reasons. In that case, the upgrade sequence will run again during the next MySQL server start. If the server upgrade fails repeatedly, the server can be started with the --upgrade=MINIMAL option to start the server without executing the upgrade sequence, thus allowing users to manually rectify the problem.

大概意思就是mysql_upgrade命令已经被丢弃了,不再使用mysql_upgrade进行更新mysql,oracle官网解释,另外我发现我的mysql版本已经是最新的了,没法更新,所以不是这个问题。只能再次查找万能的google。

终于找到原因了,感谢这位博主的解释-博文链接,就是说,mysql安装后,需要手动进行初始化的操作。

使用mysql_install_db在 MySQL 服务器好后,在使用之前,必须执行的初始化任务:

它初始化 MySQL 数据目录并创建它包含的系统表。

它初始化管理InnoDB表所需的系统表空间和相关数据结构。

它加载 server-side 帮助表。

它安装sys schema。

它创建一个管理帐户。

参考mysql5.7中文文档的解释,发现mysql_install_db命令在5.6之后就被废弃了,使用新的初始化方式:mysqld --initialize --user=mysql

这时候可能还会报错,如下:

-04-19T16:27:20.161959Z 0 [System] [MY-013169] [Server] /usr/local/Cellar/mysql/8.0.19/bin/mysqld (mysqld 8.0.19) initializing of server in progress as process 57630

-04-19T16:27:20.170544Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.

-04-19T16:27:20.170568Z 0 [ERROR] [MY-013236] [Server] The designated data directory /usr/local/var/mysql/data/ is unusable. You can remove all files that the server added to it.

-04-19T16:27:20.170649Z 0 [ERROR] [MY-010119] [Server] Aborting

-04-19T16:27:20.173505Z 0 [System] [MY-010910] [Server] /usr/local/Cellar/mysql/8.0.19/bin/mysqld: Shutdown complete (mysqld 8.0.19) Homebrew.

大概意思就是说,初始化的时候,/usr/local/var/mysql/data文件夹必须是空的,不能有任何文件,这好办,直接删除里面的文件,里面文件是mysql的数据文件:数据表文件、日志文件、索引文件等,如果是老数据库一定要先备份数据库之后才能重新初始化,否则数据会被全部删除。删除后,重新直接上面的初始化命令之后,重新启动mysql。

mysql.server start,终于启动成功了。

Starting MySQL

.. SUCCESS!

总结:对于一件完全没有接触或者不了解的问题,很多时候,第一想法就是,网上查找解决方案,因为没有接触,所以完全没有能力分辨出网上的解决方案是否有效,所以只能挨个测试,这样很浪费时间,并且有可能把电脑整出问题。在安装的过程中,忘记了自己也是一名程序员,应该有排查bug的能力。时刻记着,在遇到问题时,不管有没有接触过,也要懂得使用自己掌握的能力去解决新问题!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。