无法从MySQL中删除行

时间:2010-03-17 00:03:18

标签: mysql database delete-row

我有一张表,不会删除一行。具体来说,当我尝试删除GEO_SHAPE_ID超过150000000的任何行时,它就不会从数据库中消失。

我试过了:

  1. SQLyog将其删除。
  2. DELETE FROM TABLE WHERE GEO_SHAPE_ID = 150000042 (0行 受影响的)。
  3. UNLOCK TABLES 然后2。
  4. 据我所知,bigint是auto_increment的有效候选者。任何人都知道什么可以起来? 每当我执行上述任何操作并刷新表列表时,该行都会重新出现。 你必须帮助我们,Doc。我们已经尝试过了,我们都没有想法!

    DJS。

    编辑:根据Daniel Vassallo的建议:

    mysql> SELECT * FROM `GEO_SHAPE` WHERE GEO_SHAPE_ID = 150000042;
    Empty set (0.01 sec)
    

    答案:在MySQL中发现'check'和'repair'命令后,我发现了损坏的密钥,因此修复了这些密钥并且有效。

    PS。这是表格构造和一些仅为咯咯笑的样本数据。

    CREATE TABLE `GEO_SHAPE` (
      `GEO_SHAPE_ID` bigint(11) NOT NULL auto_increment,
      `RADIUS` float default '0',
      `LATITUDE` float default '0',
      `LONGITUDE` float default '0',
      `SHAPE_TYPE` enum('Custom','Region') default NULL,
      `PARENT_ID` int(11) default NULL,
      `SHAPE_POLYGON` polygon default NULL,
      `SHAPE_TITLE` varchar(45) default NULL,
      `SHAPE_ABBREVIATION` varchar(45) default NULL,
      PRIMARY KEY  (`GEO_SHAPE_ID`)
    ) ENGINE=MyISAM AUTO_INCREMENT=150000056 DEFAULT CHARSET=latin1 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC;
    
    SET FOREIGN_KEY_CHECKS = 0;
    
    LOCK TABLES `GEO_SHAPE` WRITE;
    INSERT INTO `GEO_SHAPE` (`GEO_SHAPE_ID`, `RADIUS`, `LATITUDE`, `LONGITUDE`, `SHAPE_TYPE`, `PARENT_ID`, `SHAPE_POLYGON`, `SHAPE_TITLE`, `SHAPE_ABBREVIATION`) VALUES (57, NULL, NULL, NULL, 'Region', 10, NULL, 'Washington', 'WA');
    INSERT INTO `GEO_SHAPE` (`GEO_SHAPE_ID`, `RADIUS`, `LATITUDE`, `LONGITUDE`, `SHAPE_TYPE`, `PARENT_ID`, `SHAPE_POLYGON`, `SHAPE_TITLE`, `SHAPE_ABBREVIATION`) VALUES (58, NULL, NULL, NULL, 'Region', 10, NULL, 'West Virginia', 'WV');
    INSERT INTO `GEO_SHAPE` (`GEO_SHAPE_ID`, `RADIUS`, `LATITUDE`, `LONGITUDE`, `SHAPE_TYPE`, `PARENT_ID`, `SHAPE_POLYGON`, `SHAPE_TITLE`, `SHAPE_ABBREVIATION`) VALUES (59, NULL, NULL, NULL, 'Region', 10, NULL, 'Wisconsin', 'WI');
    INSERT INTO `GEO_SHAPE` (`GEO_SHAPE_ID`, `RADIUS`, `LATITUDE`, `LONGITUDE`, `SHAPE_TYPE`, `PARENT_ID`, `SHAPE_POLYGON`, `SHAPE_TITLE`, `SHAPE_ABBREVIATION`) VALUES (150000042, 10, -33.8833, 151.217, 'Custom', NULL, NULL, 'Sydney%2C%20New%20South%20Wales%20%2810km%20r', NULL);
    INSERT INTO `GEO_SHAPE` (`GEO_SHAPE_ID`, `RADIUS`, `LATITUDE`, `LONGITUDE`, `SHAPE_TYPE`, `PARENT_ID`, `SHAPE_POLYGON`, `SHAPE_TITLE`, `SHAPE_ABBREVIATION`) VALUES (150000043, 10, -33.8833, 151.167, 'Custom', NULL, NULL, 'Annandale%2C%20New%20South%20Wales%20%2810km%', NULL);
    INSERT INTO `GEO_SHAPE` (`GEO_SHAPE_ID`, `RADIUS`, `LATITUDE`, `LONGITUDE`, `SHAPE_TYPE`, `PARENT_ID`, `SHAPE_POLYGON`, `SHAPE_TITLE`, `SHAPE_ABBREVIATION`) VALUES (150000048, 10, -27.5, 153.017, 'Custom', NULL, NULL, 'Brisbane%2C%20Queensland%20%2810km%20radius%2', NULL);
    INSERT INTO `GEO_SHAPE` (`GEO_SHAPE_ID`, `RADIUS`, `LATITUDE`, `LONGITUDE`, `SHAPE_TYPE`, `PARENT_ID`, `SHAPE_POLYGON`, `SHAPE_TITLE`, `SHAPE_ABBREVIATION`) VALUES (150000045, 10, 43.1002, -75.2956, 'Custom', NULL, NULL, 'New%20York%20Mills%2C%20New%20York%20%2810km%', NULL);
    INSERT INTO `GEO_SHAPE` (`GEO_SHAPE_ID`, `RADIUS`, `LATITUDE`, `LONGITUDE`, `SHAPE_TYPE`, `PARENT_ID`, `SHAPE_POLYGON`, `SHAPE_TITLE`, `SHAPE_ABBREVIATION`) VALUES (150000046, 10, 40.1117, -78.9258, 'Custom', NULL, NULL, 'Region1', NULL);
    UNLOCK TABLES;
    
    SET FOREIGN_KEY_CHECKS = 1;
    

3 个答案:

答案 0 :(得分:3)

问题是一张腐败的表格。我用“CHECK TABLE GEO_SHAPE”修正了这个问题;'然后' REPAIR TABLE GEO_SHAPE;

答案 1 :(得分:3)

转到Sequel Pro右上角的Console。右键单击无法运行的命令并将其复制。

将其粘贴到Sequel Pro顶部的Query部分并手动运行。

这将允许您查看阻止删除行的错误并修复它。

答案 2 :(得分:2)

只是尝试使用您的数据,它按预期工作:

DELETE FROM `GEO_SHAPE` WHERE GEO_SHAPE_ID = 150000042;
-- Query OK, 1 row affected (0.00 sec)

结果:

+--------------+--------+----------+-----------+------------+-----------+---------------+-----------------------------------------------+--------------------+
| GEO_SHAPE_ID | RADIUS | LATITUDE | LONGITUDE | SHAPE_TYPE | PARENT_ID | SHAPE_POLYGON | SHAPE_TITLE                                   | SHAPE_ABBREVIATION |
+--------------+--------+----------+-----------+------------+-----------+---------------+-----------------------------------------------+--------------------+
|           57 |   NULL |     NULL |      NULL | Region     |        10 | NULL          | Washington                                    | WA                 | 
|           58 |   NULL |     NULL |      NULL | Region     |        10 | NULL          | West Virginia                                 | WV                 | 
|           59 |   NULL |     NULL |      NULL | Region     |        10 | NULL          | Wisconsin                                     | WI                 | 
|    150000043 |     10 | -33.8833 |   151.167 | Custom     |      NULL | NULL          | Annandale%2C%20New%20South%20Wales%20%2810km% | NULL               | 
|    150000048 |     10 |    -27.5 |   153.017 | Custom     |      NULL | NULL          | Brisbane%2C%20Queensland%20%2810km%20radius%2 | NULL               | 
|    150000045 |     10 |  43.1002 |  -75.2956 | Custom     |      NULL | NULL          | New%20York%20Mills%2C%20New%20York%20%2810km% | NULL               | 
|    150000046 |     10 |  40.1117 |  -78.9258 | Custom     |      NULL | NULL          | Region1                                       | NULL               | 
+--------------+--------+----------+-----------+------------+-----------+---------------+-----------------------------------------------+--------------------+

你有没有尝试过:

SELECT * FROM `GEO_SHAPE` WHERE GEO_SHAPE_ID = 150000042;