[英]mysqldump: Got error: 1146: Table ' myDatabase.table' doesn't exist when using LOCK TABLES
I'm trying to get dump of my database:我正在尝试转储我的数据库:
mysqldump myDatabase > myDatabase.sql
but I'm getting this error:但我收到此错误:
mysqldump: Got error: 1146: Table 'myDatabase.table' doesn't exist when using LOCK TABLES
When I go to mysql:当我去mysql时:
mysql -u admin -p
I query for the tables:我查询表:
show tables;
I see the table.我看到了桌子。 but when I query for that particular table:
但是当我查询该特定表时:
select * from table;
I get the same error:我犯了同样的错误:
ERROR 1146 (42S02): Table 'myDatabase.table' doesn't exist
I tried to repair:我试图修复:
mysqlcheck -u admin -p --auto-repair --check --all-databases
but get the same error:但得到同样的错误:
Error : Table 'myDatase.table' doesn't exist
Why I'm getting this error or how can I fix this error?为什么我会收到此错误或如何修复此错误?
I'll really appreciate your help我会非常感谢你的帮助
对我来说,问题是通过转到/var/lib/mysql (或存储原始数据库文件的任何地方)并删除错误表示不存在的表的 .frm 文件来解决的。
I had an issue with doing mysqldump on the server, I realized that tables that if that tables were not used for longer time, then I do not need those (old applications that were shutdown).我在服务器上执行 mysqldump 时遇到问题,我意识到如果长时间不使用这些表,那么我就不需要这些表(已关闭的旧应用程序)。
The case: Cannot do backup with mysqldump, there are tables that are not needed anymore and are corrupted案例:无法用mysqldump做备份,有些表不再需要并且已损坏
At first I get the list of corrupted tables起初我得到损坏表的列表
mysqlcheck --repair --all-databases -u root -p"${MYSQL_ROOT_PASSWORD}" > repair.log
Then I analyze the log with a Python script that takes it at stdin (save as ex. analyze.py and do cat repair.log| python3 analyze.py)然后我用一个 Python 脚本分析日志,该脚本在 stdin 中获取它(另存为 ex.analyze.py 并执行 cat repair.log| python3 analyze.py)
#!/usr/bin/env python3
import re
import sys
lines = sys.stdin.read().split("\n")
tables = []
for line in lines:
if "Error" in line:
matches = re.findall('Table \'([A-Za-z0-9_.]+)\' doesn', line)
tables.append(matches[0])
print('{', end='')
print(",".join(tables), end='')
print('}', end='')
You will get a list of corrupted databases.您将获得损坏的数据库列表。
Do an export with mysqldump使用 mysqldump 进行导出
mysqldump -h 127.0.0.1 -u root -p"${MYSQL_ROOT_PASSWORD}" -P 3306 --skip-lock-tables --add-drop-table --add-drop-database --add-drop-trigger --all-databases --ignore-table={table1,table2,table3 - here is output of the previous command} > dump.sql
Turn off the database, move /var/lib/mysql to /var/lib/mysql-backup, start database.关闭数据库,将/var/lib/mysql移动到/var/lib/mysql-backup,启动数据库。
On a clean database just import the dump.sql, restart database, enjoy an instance without corrupted tables.在干净的数据库上只需导入 dump.sql,重新启动数据库,享受一个没有损坏表的实例。
I recently came across a similar issue on an Ubuntu server that was upgraded to 16.04 LTS.我最近在升级到 16.04 LTS 的 Ubuntu 服务器上遇到了类似的问题。 In the process, MySQL was replaced with MariaDB and apparently the old database couldn't be automatically converted to a compatible format.
在此过程中,MySQL 被 MariaDB 取代,显然旧数据库无法自动转换为兼容格式。 The installer moved the original database from
/var/lib/mysql
to /var/lib/mysql-5.7
.安装程序将原始数据库从
/var/lib/mysql
到/var/lib/mysql-5.7
。
Interestingly, the original table structure was present under the new /var/lib/mysql/[database_name]
in the .frm
files.有趣的是,原始表结构存在于
.frm
文件中的新/var/lib/mysql/[database_name]
。 The new ibdata file was 12M and the 2 logfiles were 48M, from which I concluded, that the data must be there, but later I found that initializing a completely empty database results in similar sizes, so that's not indicative.新的 ibdata 文件是 12M,2 个日志文件是 48M,从中我得出结论,数据必须在那里,但后来我发现初始化一个完全空的数据库会导致类似的大小,所以这不是指示性的。
I installed 16.04 LTS on a VirtualBox, installed MySQL on it, then copied the mysql-5.7
directory and renamed it to mysql
.我在 VirtualBox 上安装了 16.04 LTS,在其上安装了 MySQL,然后复制了
mysql-5.7
目录并将其重命名为mysql
。 Started the server and dumped everything with mysqldump
.启动服务器并使用
mysqldump
转储所有内容。 Deleted the /var/lib/mysql
on the original server, initialized a new one with mysql_install_db
and imported the sql file from mysqldump.删除原服务器上的
/var/lib/mysql
,用mysql_install_db
初始化一个新的,并从mysqldump中导入sql文件。
Note: I was not the one who originally did the system upgrade, so there may be a few details missing, but the symptoms were similar to yours, so maybe this could help.注意:我不是最初进行系统升级的人,所以可能缺少一些细节,但症状与您的相似,所以也许这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.