无法从 MySQL 中删除行

发布于 2024-08-26 00:09:33 字数 3284 浏览 4 评论 0原文

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

我尝试过:

  1. SQLyog来删除它。
  2. 从表中删除 GEO_SHAPE_ID = 150000042(0 行 做作的)。
  3. 解锁表然后 2.

据我所知,bigint 是 auto_increment 的有效候选者。有人知道会发生什么吗? 每当我执行上述任何操作并刷新表列表时,该行都会重新出现。 你必须帮助我们,博士。我们什么也没有尝试过,我们都没有主意了!

DJ。

编辑:根据 Daniel Vassallo 的建议:

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

答案:在 MySQL 中发现“检查”和“修复”命令后,我发现了损坏的密钥,因此修复了它们并且它起作用了。

附言。这是表结构和一些示例数据,仅供大家搞笑。

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;

I've got a table, which won't delete a row. Specifically, when I try to delete any row with a GEO_SHAPE_ID over 150000000 it simply does not disappear from the DB.

I have tried:

  1. SQLyog to erase it.
  2. DELETE FROM TABLE WHERE
    GEO_SHAPE_ID = 150000042
    (0 rows
    affected).
  3. UNLOCK TABLES then 2.

As far as I am aware, bigint is a valid candidate for auto_increment. Anyone know what could be up?
Whenever I perform any of the above operations and refresh the table listing, the row re-appears.
You gotta help us, Doc. We’ve tried nothin’ and we’re all out of ideas!

DJS.

EDIT: as per Daniel Vassallo's suggestion:

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

ANSWER: After discovering the 'check' and 'repair' commands in MySQL, I found corrupt keys, so fixed those and it worked.

PS. Here is the table construct and some sample data just for giggles.

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

忘羡 2024-09-02 00:09:33

转到 Sequel Pro 右上角的控制台。右键单击运行失败的命令并将其复制。

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

这将使您能够看到阻止该行被删除的错误并修复它。

Go to the Console, in the top-right corner of Sequel Pro. Right-click on the command that failed to run and copy it.

Paste it into the Query section at the top of Sequel Pro and run it manually.

That will allow you to see the error that is preventing the row from being deleted and fix it.

悲歌长辞 2024-09-02 00:09:33

刚刚用您的数据尝试过,它按预期工作:

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;

Just tried it with your data, and it worked as expected:

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

Result:

+--------------+--------+----------+-----------+------------+-----------+---------------+-----------------------------------------------+--------------------+
| 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               | 
+--------------+--------+----------+-----------+------------+-----------+---------------+-----------------------------------------------+--------------------+

Did you try:

SELECT * FROM `GEO_SHAPE` WHERE GEO_SHAPE_ID = 150000042;
无声无音无过去 2024-09-02 00:09:33

问题是一个损坏的表。我用“CHECK TABLE GEO_SHAPE;”修复了这个问题然后'修复表GEO_SHAPE;

Problem was a corrupt table. I fixed this with 'CHECK TABLE GEO_SHAPE;' and then 'REPAIR TABLE GEO_SHAPE;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文