[英]Alter a live table to make a key non-unique
I saw some other questions related to this, but they were not MySQL.我看到了一些与此相关的其他问题,但它们不是 MySQL。
The database is a live database, so I don't want to delete and recreate the table.该数据库是一个实时数据库,所以我不想删除并重新创建表。 I simply want to make a column no longer unique, which is less permissive in nature so it shouldn't cause any problems.
我只是想让一个列不再是唯一的,这本质上是不那么宽松的,所以它不应该引起任何问题。
If your column was defined unique using UNIQUE
clause, then use:如果您的列使用
UNIQUE
子句定义为唯一的,则使用:
ALTER TABLE mytable DROP INDEX constraint_name
, or, if your constraint was implicitly named, ,或者,如果您的约束被隐式命名,
ALTER TABLE mytable DROP INDEX column_name
If it was defined unique using PRIMARY KEY
clause, use:如果使用
PRIMARY KEY
子句定义它是唯一的,请使用:
ALTER TABLE mytable DROP PRIMARY KEY
Note, however, that if your table is InnoDB
, dropping PRIMARY KEY
will result in implicit recreation of your table and rebuilding all indexes, which will lock the table and may make it inaccessible for quite a long time.但是请注意,如果您的表是
InnoDB
,删除PRIMARY KEY
将导致您的表隐式重建并重建所有索引,这将锁定表并可能使其在很长一段时间内无法访问。
These are instructions for phpmyadmin app (if you are using phpMyAdmin) ::这些是 phpmyadmin 应用程序的说明(如果您使用的是 phpMyAdmin)::
In a some cases, the developer (you) may not want to drop it but rather just modify the "uniqueness" to "not-unique".在某些情况下,开发人员(您)可能不想放弃它,而只是将“唯一性”修改为“非唯一性”。
Steps :脚步 :
Go to the table in context, where you want to make the modification转到上下文中的表,您要在其中进行修改
Click on the "Structure" tab (mostly next to Browse)单击“结构”选项卡(主要在浏览旁边)
Answer was found here : Source : https://forums.phpfreaks.com/topic/164827-phpmyadmin-how-to-make-not-unique/在这里找到答案:来源: https ://forums.phpfreaks.com/topic/164827-phpmyadmin-how-to-make-not-unique/
Just DROP
the unique index.只需
DROP
唯一索引。 There shouldn't be a problem with the fact that it is a live DB.它是一个实时数据库这一事实应该没有问题。 If it is a really large table, you may block some queries temporarily while the index is removed.
如果它是一个非常大的表,您可能会在删除索引时暂时阻止一些查询。 But that should only happen if you were adding an index.
但这只有在您添加索引时才会发生。
ALTER TABLE table_name DROP INDEX index_name;
Although the accepted answer is incorrect (see comments), the suggested workaround is possible.尽管接受的答案不正确(请参阅评论),但建议的解决方法是可能的。 But it is not correct too, at least for a "live table", as asked.
但这也不正确,至少对于“现场餐桌”来说,正如所问的那样。
To lower the impact you should create a new index at first, and then delete the old one:为了降低影响,您应该首先创建一个新索引,然后删除旧索引:
ALTER TABLE mytable ADD INDEX idx_new (column);
ALTER TABLE mytable DROP INDEX idx_old;
This avoids using the table (column) without index at all, which can be quite painful for clients and the MySQL itself.这避免了使用没有索引的表(列),这对于客户端和 MySQL 本身来说都是非常痛苦的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.