MySQL - 表不存在且无法创建

时间:2016-05-16 13:19:00

标签: mysql mysql-5.5

MySQL 5.5.46奇怪错误:表不存在且无法创建。

拜托,有人可以帮忙吗?

drop table t_example;

返回:drop table t_example错误代码:1051。未知表't_example'0.000秒

CREATE TABLE  t_example(
  `id_example` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `des_example` VARCHAR(45) NOT NULL,
  `id_example` int unsigned NULL,
  PRIMARY KEY (`id_example`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;

返回:错误代码:1050。表't_example'已存在

select * from t_example;

返回:错误代码:1146。表't_example'不存在

我正在使用:

  • UBUNTU 14.04 LTS;
  • mysql Ver 14.14使用readline 6为debian-linux-gnu(x86_64)分发 5.5.46
  • 我正在使用root用户。

尝试:

mysql> REPAIR TABLE t_example;
+----------------+--------+----------+--------------------------------------+
| Table          | Op     | Msg_type | Msg_text                             |              
+ ---------------+--------+----------+--------------------------------------+
| mydb.t_example | repair | Error    | Table 'mydb.t_example' doesn't exist |
| mydb.t_example | repair | status   | Operation failed                     |              
+----------------+--------+----------+--------------------------------------+
2 rows in set (0.00 sec)

也试过:sudo mysqladmin flush-tables ...也没解决问题!

实例:

mysql> use flexible;
Database changed
mysql> select * from  st_fin_centro_custo;
ERROR 1146 (42S02): Table 'flexible.st_fin_centro_custo' doesn't exist
mysql> CREATE TABLE  st_fin_centro_custo(
    ->   `cod_centro_custo` INT UNSIGNED NOT NULL AUTO_INCREMENT,
    ->   `des_centro_custo` VARCHAR(45) NOT NULL,
    ->   PRIMARY KEY (`cod_centro_custo`))
    ->   ENGINE = InnoDB
    -> DEFAULT CHARACTER SET = utf8
    -> COLLATE = utf8_general_ci;
ERROR 1050 (42S01): Table '`flexible`.`st_fin_centro_custo`' already exists
mysql> drop table st_fin_centro_custo;
ERROR 1051 (42S02): Unknown table 'st_fin_centro_custo'
mysql>

尝试从MySQL information_schema获取:

    mysql> SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_TYPE 
FROM information_schema.tables 
where table_name like 'st_fin_centro_custo';
    Empty set (0.00 sec)

    mysql>

注意:使用其他名称创建表格可以正常工作。

非常感谢!

3 个答案:

答案 0 :(得分:1)

First select your data base schema by using use command<use schema>. 
Then run DROP TABLE IF EXISTS t_example;
After that try to create your table 

CREATE TABLE  t_example(
  `id_example` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `des_example` VARCHAR(45) NOT NULL,
  PRIMARY KEY (`id_example`))
ENGINE = INNODB
DEFAULT CHARACTER SET = UTF8
COLLATE = UTF8_GENERAL_CI;

Also don't use duplicate column name.

Another solution is : 

 Change table name in the create table query, execute it and then rename the table.

Then, you can also drop this table and after it create it without getting error.

答案 1 :(得分:0)

您的桌子可能已损坏。

尝试REPAIR TABLE t_example;

答案 2 :(得分:0)

首先,尝试重新启动mysqld。如果没有帮助,请尝试将此表创建到另一个数据库中。然后将新创建的*.frm文件复制到目标数据库文件夹。再次重启mysqld。现在尝试在适当的DB中访问/删除/创建此表。

编辑:如何从头开始删除数据库并重新创建?我希望它不是一个生产系统。