MySQL,复制表文件会导致“错误 1017 (HY000):找不到文件:”即使它在那里

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12106727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 14:36:23  来源:igfitidea点击:

MySQL, copying tables files gives rise to "ERROR 1017 (HY000): Can't find file:" even though its there there

mysql

提问by user1622094

I want to copy the database tables from my production server to a local test machine so I can perform test om (copies of) the real data.

我想将数据库表从我的生产服务器复制到本地测试机器,以便我可以对真实数据执行测试 om(副本)。

I stopped mysql and deleted all the frm, MYD and MYI files. Starting mysql here and querying show tables gives an empty result set. I then shut down mysql and copied all the frm, MYD and MYI files from the server. When starting mysql "show tables" shows the tables as expected but trying to query them I get the error message

我停止了 mysql 并删除了所有的 frm、MYD 和 MYI 文件。在这里启动 mysql 并查询 show tables 给出一个空的结果集。然后我关闭 mysql 并从服务器复制所有 frm、MYD 和 MYI 文件。当启动mysql“show tables”按预期显示表但尝试查询它们时,我收到错误消息

ERROR 1017 (HY000): Can't find file: './WhateverTableIQuery.frm' (errno: 13)

错误 1017 (HY000): 找不到文件: './WhateverTableIQuery.frm' (errno: 13)

But the WhateverTableIQuery.frm file is on the disc and is identical to the one on the server.

但是WhateverTableIQuery.frm 文件在光盘上并且与服务器上的相同。

Any ideas about what might be the problem?

关于可能是什么问题的任何想法?

回答by Tom Mac

I'd suggest giving two things a try:

我建议尝试两件事:

1. Check Permissions

1.检查权限

Make sure that your MySQL data directory and all the files in it are owned by mysql user and mysql group. This may not be the case if you copied the files onto your local test machine as root user:

确保您的 MySQL 数据目录及其中的所有文件都归 mysql 用户和 mysql 组所有。如果您以 root 用户身份将文件复制到本地测试机器上,则情况可能并非如此:

chown -R mysql:mysql your-mysql-data-dir-here

2. Repair corrupted tables

2. 修复损坏的表

Use mysqlcheckto check for corrupted tables and repair them if it finds any:

使用mysqlcheck检查损坏的表并在发现任何表时修复它们:

mysqlcheck -u root -p --auto-repair --all-databases

If you still can't use the tables after that then give mysqldump a go!

如果在那之后您仍然无法使用这些表,那么请试一试mysqldump!

回答by Indika K

I encountered the same issue after restoring a MySQL database with frm and MYD files. After a number of hours spent I observed that I have configured the database directory with only read and write permission to mysql user but not execute permission. After adding execute permission to the database directory, the problem was solved.

使用 frm 和 MYD 文件恢复 MySQL 数据库后,我遇到了同样的问题。花了几个小时后,我观察到我配置的数据库目录只有对 mysql 用户的读写权限,但没有执行权限。给数据库目录添加执行权限后,问题解决。

回答by Philipp Meissner

I did have the very same issue a couple minutes ago and it took me a few minutes to realize that I had insufficient permission to access the .sql file I wanted to import.

几分钟前我确实遇到了同样的问题,我花了几分钟才意识到我没有足够的权限来访问我想要导入的 .sql 文件。

In order to get rid of this problem you could just move the file to a place you know you have access to (with your current user) for sure. (eg. ~/Home_directory).

为了摆脱这个问题,您可以将文件移动到您知道您可以访问(与您的当前用户)的地方。(例如~/Home_directory)。

I hope I could help some lonely soul that was searching for the answer just like I was.

我希望我能帮助一些像我一样寻找答案的孤独灵魂。

回答by Saul

I had the same issue and did this...

我有同样的问题,并做了这个......

  • Delete Migrations Folder
  • Drop the _migrationhistory table
  • Enable, Add and Update migration
  • 删除迁移文件夹
  • 删除 _migrationhistory 表
  • 启用、添加和更新迁移

I'm sure there's a much better way to solve this but, it worked for me.

我确信有更好的方法来解决这个问题,但是,它对我有用。

回答by supb

I changed permissions for the mysql-data-directory as well as the <table>.frmfile.
If using as root user:

我更改了 mysql-data-directory 和<table>.frm文件的权限。
如果作为 root 用户使用:

  • chmod 600 mysql-data-directory chmod 600
  • mysql-data-directory/tableOfData.frm
  • chmod 600 mysql 数据目录 chmod 600
  • mysql 数据目录/tableOfData.frm

If using as non-root user:

如果作为非 root 用户使用:

  • chmod 660 mysql-data-directory
  • chmod 660 mysql-data-directory/tableOfData.frm
  • chmod 660 mysql 数据目录
  • chmod 660 mysql 数据目录/tableOfData.frm

回答by Alexandre Keller

This error, "General error: 1017 Can't find file", also happened on Windows with WAMP if the table doesn't exist.

如果该表不存在,则此错误“一般错误:1017 找不到文件”也会在使用 WAMP 的 Windows 上发生。

回答by Farzoqe Khan

Try following things:

尝试以下事情:

  • repair whole database
  • change permission to mysql:mysql
  • restart mysql service
  • 修复整个数据库
  • 更改 mysql:mysql 的权限
  • 重启mysql服务

One of these will work.

其中之一将起作用。