MySQL创建表错误 - 表不存在

时间:2022-02-15 08:23:24

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

ERROR 1146(42S02):表'recommended.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

ERROR 1146(42S02):表'recommended.Users'不存在

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

我也尝试使用Navicat仍然得到相同的错误:(

3 个解决方案

#1


4  

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 .frm file to the current database. Then you can DROP the table, and a subsequent CREATE should then succeed. More details on troubleshooting this sort of problem can be found here

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

#2


9  

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;

DROP TABLE用户;

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 /系统管理员/黑客。

#3


0  

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

#1


4  

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 .frm file to the current database. Then you can DROP the table, and a subsequent CREATE should then succeed. More details on troubleshooting this sort of problem can be found here

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

#2


9  

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;

DROP TABLE用户;

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 /系统管理员/黑客。

#3


0  

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