MySQL表不存在错误,但它确实存在
有谁知道在什么条件下您可以收到 1146: Table '
我在 5 台服务器上使用相同的代码,只有我最近租用的一台服务器显示此错误,因此我怀疑这可能是某种设置或安装错误。我可以从命令行执行我的sql语句。显然,我也可以从命令行查看该表。当我建立连接时,我没有收到任何连接错误(顺便说一句,我正在使用 mysqli)。
任何帮助将不胜感激。
精确查询:
$sql = "SELECT DISTINCT(mm_dic_word) AS word FROM spider.mm_dictionary WHERE mm_dic_deleted=0";
Does anyone know under what conditions you can receive an 1146: Table '<database>.<table>' doesn't exist
error when your table does, in fact, exist?
I use the same code on 5 servers, only one that I recently rented is showing this error, so I suspect it may be a settings or install error of some kind. I can execute my sql statement from the command line just fine. I can, obviously, see the table from the command line as well. I don't get any connection errors when I establish a connection (I'm using mysqli, btw).
Any help would be appreciated.
exact query:
$sql = "SELECT DISTINCT(mm_dic_word) AS word FROM spider.mm_dictionary WHERE mm_dic_deleted=0";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
我在带有 mysql 5.1 和 xfs 文件系统的 centos 6.4 系统上看到过这个。
这些表显示为“显示表”,但选择或描述失败,并显示表不存在消息,如您所描述的。这些文件位于我期望的位置。
系统运行良好几个月,然后在更改 /etc/my.cnf 将 table_cache 设置为 512 而不是 256 后重新启动服务 mysqld 后,系统出现了偏差。
根据 arcconf,raid 控制器认为一切都很好。 xfs_check 没有找到任何东西。 IPMI的系统事件列表一目了然。 dmesg 显示了 iptables 关于连接跟踪和丢弃软件包的一些抱怨,所以我们可能已经被 DOS 了,但由于服务器上没有任何东西真正面向外部运行,我不明白它如何影响 mysql 数据完整性?
我最终将slave提升为master并重新加载系统,现在想知道是什么导致了错误,以及centos 6.4上xfs的选择是否仍然是一个稳定的选择,或者罪魁祸首是否是mysql 5.1。
哦,是的,永远不要改变正在运行的系统:)
I have seen this on a centos 6.4 system with mysql 5.1 and an xfs filesystem.
The tables show with 'show tables' but a select or describe fails with the table not existing message as you described. The files are where I expect them to be.
The system was running fine for months, then after a service mysqld restart after changing /etc/my.cnf to set table_cache to 512 instead of 256, it went sideways.
According to arcconf the raid controller thinks everything is fine. xfs_check does not find anything. the system-event-list of IPMI is clear. dmesg shows some complaints by iptables about connection tracking and dropping packages, so we may have been DOS'd, but since there is nothing really running outside facing on the server I don't see how it could affect mysql data integrity?
I ended up promoting the slave to master and reloading the system, and now am wondering what could have caused the error, and if the choice of xfs on centos 6.4 is still a stable choice, or if the culprit was mysql 5.1.
Oh yeah and never change a running system :)
Mac OS X?
停下来,不要重新复制任何东西...
我在 Mavericks 上遇到过几次这个问题。 MySQL 不再包含在内,但我认为我的安装基本上与您期望在 Snow Leopard 上找到的安装相同,而不是 MAMP 或其他东西。
从一台计算机迁移到另一台计算机后,我遇到了这个问题。这是MySQL控制面板启动mysqld的结果,而不是我在命令行启动它的结果。 (迁移时,这个有点过时的控制面板忘记了您告诉它不要在启动时启动。)
查看我的系统上的进程(顶部或活动监视器):如果所有者是root,则它是由launched启动的,并且不会正常工作;正确的进程将以 _mysql 作为所有者。
有时,我有两个进程并行运行!
奇怪的是,你可以做任何事情,包括通过命令行使用 mysql。但是,即使列出了 innodb 表,它们也会在查询时生成不存在错误。
这似乎是一个所有权问题,也可能适用于其他系统。
Mac OS X?
STOP, don't recopy anything yet...
I had this problem a couple of times on Mavericks. MySQL is no longer included, but my install is essentially the same as what you'd expect to find on Snow Leopard, I think, rather than MAMP or something.
After migrating from one computer to another I had this problem. It was the result of the MySQL control panel starting mysqld, rather than my starting it on the command line. (When migrating, this somewhat obsolete control panel forgets that you told it NOT to start on boot.)
Look at the processes (top or activity monitor), on my system: if owner is root, it was started by launched and doesn't work properly; the correct process will have _mysql as owner.
Sometimes, I have both process running side by side!
Oddly, you can do everything, including use mysql via command line. However, even though innodb tables are listed they generate a do not exist error on querying.
This seems to be an ownership issue, which may apply on other systems as well.
您最好使用 mysqldump 对要备份的表进行正确的 SQL 类型备份。复制内部文件经常会导致这样的问题。
例如
,然后复制并执行:
会省去很多麻烦:)
You are ALWAYS better off doing proper SQL type backups with mysqldump for the tables you're wanting to backup. Copying the internal files very often leads to problems like this.
e.g.
then copying over and doing:
Will save a lot of headaches :)
如果您以无权查看该数据库/表的用户身份登录,那么您可能会得到该结果。您在命令行上使用的登录名是否与通过 mysqli 使用的登录名相同?
If you're logged in as someone who doesn't have permission to view that database/table then you'll probably get that result. Are you using the same login on the command line as you are through mysqli?
这恰好发生在我身上,过了一会儿,我在一篇博客文章中找到了答案,也想把它放在这里。
如果将 MySQL 数据目录从
/var/lib/mysql
复制到/path/to/new/dir
,但只复制数据库文件夹(即mysql
、wpdb
、ecommerce
等)并且您确实有 InnoDB 表,您的 innodb 表将显示在“显示表”中,但对它们进行查询(select
和describe
) 将失败,并出现错误Mysql 错误:表 db.tableName 不存在
。您将在 db 目录中看到.frm
文件,并想知道为什么。对于 InnoDB 表,复制
ib*
文件非常重要,在我的例子中是ibdata1
、ib_logfile0
和ib_logfile1< /代码>。当我完成传输并确保将其复制过来后,一切都按预期进行。
如果您的
my.cnf
文件包含innodb_file_per_table
,则.ibd
文件将出现在 db 目录中,但您仍然需要ib*
文件。This just happened to me and after a while I found the answer on a blog article, and wanted to put it here as well.
If you copy the MySQL data directory from
/var/lib/mysql
to/path/to/new/dir
, but only copy the database folders (i.e.mysql
,wpdb
,ecommerce
, etc) AND you do have InnoDB tables, your innodb tables will show up in 'show tables' but queries on them (select
anddescribe
) will fail, with the errorMysql error: table db.tableName doesn't exist
. You'll see the.frm
file in the db directory, and wonder why.For InnoDB tables, it's important to copy over the
ib*
files, which in my case wereibdata1
,ib_logfile0
, andib_logfile1
. Once I did the transfer making sure to copy those over, everything worked as expected.If your
my.cnf
file containsinnodb_file_per_table
the.ibd
file will be present in the db directory but you still need theib*
files.在这种情况下,使用 mysqlcheck 是正确的 - 所以你可以放弃表健全性问题和表完整性问题。如果需要的话修理它们。
Using the mysqlcheck would be in order in this case - so you can discard table sanity problems & repair them if neeeded.
难道你的一台服务器是linux机器吗? MySQL在linux上区分大小写,在windows上不区分大小写。
Could it be that your one server is a linux box? Mysql is case sensitive on linux but insensitive on windows.
基本上,我相信我遇到的问题是由于密码哈希长度不同造成的。就我而言,我得到了一台新服务器,在其上进行了完整的 mysql 转储,还传输了密码和用户信息。新服务器已经使用具有 16 个字符长度哈希的 root 用户进行了初始化,但我的旧服务器正在使用较新的 32 个字符哈希长度。
我必须进入 my.conf 将旧密码设置为 0(否则每次我尝试更新数据库时,新更新的长度都是 16 个字符)。然后,我通过命令 UPDATE mysql.user SET password=PASSWORD('password here'); 将所有密码更新为相同,然后刷新权限。
显然,让每个用户使用相同的密码是一个非常糟糕的主意,所以在确认它可以工作后,我一一更改了它们。
我在这里写了一篇博客文章,介绍了我所做的一些其他事情,但这些事情不起作用,在我遇到这个解决方案之前(以防万一这些更改中的一个或多个影响我的结果),但是,我认为上述解决方案是完整的......但我还没有尝试重现该错误,所以我可以'不能100%确定。
Basically, I believe the problem that I was experiencing was due to differing password hash lengths. In my case, I got a new server, did a complete mysql dump on it which transferred passwords and user info also. The new server was already initialized with a root user that had a 16char length hash, but my old server was using the newer 32 char hash lengths.
I had to go into my.conf set the old passwords setting to 0 (other wise every time I tried updating the database, the new update was 16 chars in length). I then updated all the passwords to be the same via the command
UPDATE mysql.user SET password=PASSWORD('password here');
, then I flushed privileges.Obviously, having every user with the same password is a really bad idea, so I changed them one by one after I confirmed that it was working.
I typed up a blog entry that goes into some of the other things I did that didn't work here, before I happened upon this solution (just in case one or more of those changes effected my outcome) however, I think that the above solution to be complete... but I haven't tried to reproduce the error so I can't be 100% sure.
当我尝试使用大写字母选择表而表名是小写字母时,就发生了这种情况。
因此,为了解决这个问题,我将“lower_case_table_names=1”放在 my.cnf 文件中。
This happened to me when I was trying to select a table using UPPERCASE and the table name was lowercase.
So, to solve this question, I put "lower_case_table_names=1" on my.cnf file.
我曾经有过这样的行为。后来我发现我使用的 JDBC 驱动程序将我的查询更改为小写,因此我无法使用它访问我的数据库(使用混合大小写字母),尽管我的代码使用了正确的混合字母。
I had this kind of behaviour once. Later on I discovered that the JDBC driver I used changed my query to lower case, so I couldn't reach my database (which used mixed case letters) with it, although my code was using the correct mixed letters.
这可能与 InnoDB 和 MyISAM 表一起使用有关。如果复制数据库文件,MyISAM 会正常,而 InnoDB 会显示但无法工作。
It could be related to having InnoDB and MyISAM tables together. If you copy the database files, the MyISAM will be fine and the InnoDB will show up but fail to work.