简体   繁体   English

MySQL:具有DROP INDEX的ALTER IGNORE TABLE

[英]MySQL: ALTER IGNORE TABLE with DROP INDEX

I have many databases and in each I have table names . 我有很多数据库,每个数据库都有表names In some I have UNIQUE KEY named name1 and in others the same UNIQUE KEY is named name2 . 在某些情况下,我有名为name1 UNIQUE KEY,在其他情况下,相同的UNIQUE KEY则名为name2 I want to standard this name so I prepared 3 queries to run on each database: 我想将此名称标准化,所以我准备了3个查询以在每个数据库上运行:

ALTER IGNORE TABLE `names`
    DROP INDEX `name1`;
ALTER IGNORE TABLE `names`
    DROP INDEX `name2`;
ALTER TABLE `names`
    ADD UNIQUE `new_name` (`name`, `surname`);

But I got error: 但是我得到了错误:

SQL Error (1091): Can't DROP 'name1'; check that column/key exists

How can I make one set of queries to run on each database? 如何使一组查询在每个数据库上运行?

You can attempt to ignore errors if you're executing your SQL script file from command line: 如果您从命令行执行SQL脚本文件,则可以尝试忽略错误:

mysql -f -u username -p password -e 'source script.sql'

EDIT 编辑

Thanks to Ike, the correct way to do this is: 感谢Ike,正确的方法是:

mysql -f -u username -p password < script.sql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM