Ubuntu 20.04安装MySQL 8.0.20记

很久没手工装过MySQL了,诸如AppNode这样的服务器面板很好的帮助开发人员屏蔽了琐碎的底层环境配置问题。不过AppNode支持的系统版本都很老了,其他面板又用不惯,于是打算手工安装一次环境尝鲜下新版本。

不夸张的说,我为了装一个MySQL昨天晚上从12点折腾到凌晨3点,今天早上11点起来又折腾到13点……于是今天打算把遇到的坑总结一下,免得后人再踩进来。

目录

坑一

Ubuntu 20.04下安装mysql-server的过程中是不会要求输入root密码的,root密码被设置成了什么至今我也没弄明白。

看到网上教程以及官方文档都说安装过程中会生成一个默认密码,并被保存在错误日志里,然而我仔细翻过,发现并没有。

于是乎打算强制修改root密码,由此引出了坑二……

正确的查看管理密码的方式是:

sudo cat /etc/mysql/debian.cnf

上述文件的内容是:

可以看到user字段就是管理员用户名,password当然就是默认密码了。这个debian-sys-maint账号是Debian系Linux下MySQL的默认管理账号。

直接使用这个账号登录MySQL就可以愉快的玩耍了,如果你和我一样不幸的按照网上的坑比文章强制重设了root密码,请看“坑二”。

坑二

当时为了重置root密码,在网上搜了很多文章,大部分都是教要在/etc/mysql/my.cnf中添加skip-grant-tables;选项来跳过密码登录。

如果你这么做了,恭喜你,你完蛋了。

根据一篇台湾同胞写的文章来看,这个选项会修改mysql的用户表,造成不可预知的问题。

其具体表现的症状就是你在修改完root密码并登陆后,执行show databases;命令会弹出如下报错:

ERROR 1449 (HY000): The user specified as a definer ('mysql.infoschema'@'localhost') does not exist

这个报错着实让我头疼了一阵,谷歌搜、百度搜、官网搜,得出的结论无非就是执行mysql_upgrade -u root -p命令,尝试升级/var/lib/mysql下的数据库文件。

可是,这个命令在MySQL 8.0.16中已经被废弃了……执行后会出现如下提示:

Enter password: 
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完全卸载,并删除/var/lib/mysql目录,重新安装后再通过“坑一“中介绍的方式来查看管理员账号。

如果你必须要用root用户,可以使用这个命令重置其密码:sudo mysql_secure_installation

11 Comments on “Ubuntu 20.04安装MySQL 8.0.20记

  1. 我也是从昨晚搞到现在,,太难了,,, 以为一切ok了,结果又卡在了1449.,。。。

    现在默默卸载,,重装,太烦了

  2. 我靠啊 真的太难了 我也弄了大半天 还好看到你的解答 赶紧删了重装 救星啊

  3. 我的经历和博主几乎一模一样,除了发行版是Debian。。。现在卡在了“ERROR 1449 (HY000): The user specified as a definer (‘mysql.infoschema’@’localhost’) does not exist”

  4. 实在是太难了,一环套一环,网上的教程都是一模一样的,根边分辨不出来正确与否

    • 问题是有比服务器面板更紧急的事情等着要去折腾……如果雨露均沾的话我怕我没那么多精力

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code