mysql ERROR 1051
症状
mysql 版本:8.0.21
执行删除表命令
drop table tbl_name;
会报错ERROR 1051 (42S02): Unknown table 'demo_db.tbl_name'
。
原因
如果不是两次安装 mysql 导致 store engine 不同的话可能是因为 tbl_name 不是一个 table,而是一个 view。
平常我们使用下面的命令来列出所有表
show tables;
+-------------------+ | Tables_in_demo_db | +-------------------+ | demo_table | | demo_view | +-------------------+
但是容易被忽略的一点是该命令会连带 view 一起列出来。为了只列出 table,可以使用下面这条命令。
show full tables;
+-------------------+------------+ | Tables_in_demo_db | Table_type | +-------------------+------------+ | demo_table | BASE TABLE | | demo_view | VIEW | +-------------------+------------+
这样就可以明确知道其类型是 table 还是 view。
解决
对于 view 和 table 使用不同的语句进行删除。
服务启动失败
情况一
症状
mysql 版本:8.0.21
使用 systemctl start mysql
显示
-- Subject: Unit mysql.service has begun start-up -- Defined-By: systemd -- Support: http://www.ubuntu.com/support -- Unit mysql.service has begun starting up. Oct 16 16:36:45 VM-0-11-ubuntu audit[7397]: AVC apparmor="STATUS" operation="profile_replace" info="same as current prof Oct 16 16:36:45 VM-0-11-ubuntu kernel: audit: type=1400 audit(1602837405.154:33): apparmor="STATUS" operation="profile_r Oct 16 16:36:45 VM-0-11-ubuntu systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE Oct 16 16:36:45 VM-0-11-ubuntu systemd[1]: mysql.service: Failed with result 'exit-code'. Oct 16 16:36:45 VM-0-11-ubuntu systemd[1]: Failed to start MySQL Community Server. -- Subject: Unit mysql.service has failed -- Defined-By: systemd -- Support: http://www.ubuntu.com/support -- Unit mysql.service has failed.
查看 mysql 错误日志 cat /var/log/mysql/error.log
mysqld: File './binlog.index' not found (OS errno 13 - Permission denied)
原因
mysql 目录的所属用户和用户组不是 mysql。
解决
将配置文件中所展现出现的目录如 /var/lib/mysql
的所属用户和用户组改为 mysql。