gpt4 book ai didi

mysql - 当我尝试在 mysql 浏览器中使用此查询时,drop index indexname 无法正常工作

转载 作者:行者123 更新时间:2023-11-30 00:39:02 25 4
gpt4 key购买 nike

当我尝试drop时出现错误我的索引,或者当我尝试使用此类查询 SHOW INDEX 查看我的索引时或DROP INDEX <INDEXNAME>

错误信息是:

mysqlserver version for right syntax to use near at line 1"".

最佳答案

查看索引

show index from myTable;
+---------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+---------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| myTable | 0 | PRIMARY | 1 | id | A | 2 | NULL | NULL | | BTREE | | |
| myTable | 1 | title | 1 | title | A | 2 | NULL | NULL | YES | BTREE | | |
| myTable | 1 | price | 1 | price | A | 2 | NULL | NULL | YES | BTREE | | |
+---------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
3 rows in set (0.00 sec)

对于下降索引

ALTER TABLE TABLE_NAME DROP INDEX INDEX_NAME;

示例

show create table myTable\G
*************************** 1. row ***************************
Table: myTable
Create Table: CREATE TABLE `myTable` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`price` mediumint(9) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `title` (`title`),
KEY `price` (`price`),
KEY `idx_price_title` (`price`,`title`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
1 row in set (0.02 sec)

我需要删除索引idx_price_title

ALTER TABLE myTable DROP INDEX idx_price_title;
Query OK, 0 rows affected (0.18 sec)
Records: 0 Duplicates: 0 Warnings: 0

检查索引是否存在

show create table myTable\G
*************************** 1. row ***************************
Table: myTable
Create Table: CREATE TABLE `myTable` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`price` mediumint(9) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `title` (`title`),
KEY `price` (`price`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
1 row in set (0.00 sec)

关于mysql - 当我尝试在 mysql 浏览器中使用此查询时,drop index indexname 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21931890/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com