MySQL 创建表错误 - 表不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18034485/
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 18:24:38  来源:igfitidea点击:

MySQL Create Table Error - Table Doesn't Exist

mysql

提问by Amit P

I am new to MySQL, and I am having a problem where if I try to create a Table in my newly created Database "recommend", I get the following error:

我是 MySQL 的新手,我遇到了一个问题,如果我尝试在我新创建的数据库“推荐”中创建一个表,我会收到以下错误:

ERROR 1146 (42S02): Table 'recommend.Users' doesn't exist

错误 1146 (42S02):表 'recommend.Users' 不存在

I checked related posts here and on the internet but nothing helped. If I use the MySQL command line I still get the same error.

我在这里和互联网上查看了相关帖子,但没有任何帮助。如果我使用 MySQL 命令行,我仍然会遇到相同的错误。

SELECT DATABASE() FROM DUAL;

+------------+

| DATABASE() |

+------------+

| recommend  |

+------------+

1 row in set (0.00 sec)

but then when i run this command :

但是当我运行这个命令时:

mysql> use recommend
Database changed

mysql> CREATE TABLE Users (UserName VARCHAR(20),password VARCHAR(20),PRIMARY KEY(UserName));

ERROR 1146 (42S02): Table 'recommend.Users' doesn't exist

错误 1146 (42S02):表 'recommend.Users' 不存在

I also tried using Navicat and still get the same error :(

我也尝试使用 Navicat,但仍然出现相同的错误:(

采纳答案by Amit P

This looks like a data dictionary problem. You can get more information by checking the error log. (See the MySQL docs here).

这看起来像一个数据字典问题。您可以通过检查错误日志获得更多信息。(请参阅此处的 MySQL 文档)。

Possibly, you have an orphaned table. If so, the solution is to create a table of the same name in a different database, then copy the .frmfile to the current database. Then you can DROPthe table, and a subsequent CREATEshould then succeed. More details on troubleshooting this sort of problem can be found here

可能,您有一个孤立的表。如果是这样,解决方法是在不同的数据库中创建一个相同名称的表,然后将.frm文件复制到当前数据库中。然后你可以DROP表,随后CREATE应该成功。可以在此处找到有关解决此类问题的更多详细信息

回答by Allen

I had the same problem. I actually read this thread before I got lucky with a simple solution. I attempted to drop my table and it worked, in your case your table is User:

我有同样的问题。在我获得一个简单的解决方案之前,我实际上阅读了这个线程。我试图放下我的桌子并且它起作用了,在你的情况下你的桌子是用户:

DROP TABLE Users;

删除表用户;

The table does not exist, so naturally MySQL complains:

该表不存在,所以 MySQL 自然会抱怨:

Error Code: 1051. Unknown table 'Users'

错误代码:1051。未知表“用户”

But then I ran my CREATE TABLE statement again and it worked. Hopefully others can validate this works every time? A lot easier than going to an error log, especially if you are not the greatest DBA/System Admin/Hacker.

但是后来我再次运行了我的 CREATE TABLE 语句并且它起作用了。希望其他人每次都能验证这是否有效?比查看错误日志要容易得多,尤其是当您不是最出色的 DBA/系统管理员/黑客时。

回答by IbarMario

The Problem was... You have a DB with "InnoDB ENGINE"....... My Solution was... You must have a "MyISAM ENGINE", how to change?... find on your environment may be with

问题是......你有一个带有“InnoDB ENGINE”的数据库.......我的解决方案是......你必须有一个“MyISAM ENGINE”,如何改变?......在你的环境中找到可能是和

# find / -name my.cnf

on LINUX, simply add the following line to

在 LINUX 上,只需将以下行添加到

vim /etc/mysql/my.cnf 

Add:

添加:

default-storage-engine= MyISAM

Then restart mysql:

然后重启mysql:

service mysql restart