搜索在mysql中一次更改多个表的简单方法
我有很多以某个前缀开头的表,
我想更改此表,
执行此操作的简单方法是什么(而不是运行所有表)
我的意思是:
ALTER TABLE LIKE tablenameprefix% ADD INDEX `NewIndex1` (`field`);
我该怎么做?
谢谢
编辑:
我可以做一种不在存储过程中的循环吗? 通过选择表的名称
SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_NAME LIKE 'tableprefix%'
i have a lot of tables that start with some prefix ,
and i want to alter this tables
what is the simple way to do this (instead run over all tables)
i mean something like :
ALTER TABLE LIKE tablenameprefix% ADD INDEX `NewIndex1` (`field`);
how can i do this ?
thanks
EDIT :
can i do a kind of loop not in stored procedure ?
by select the names of tables from
SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_NAME LIKE 'tableprefix%'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你不能。您可以做的是编写一个存储过程,枚举所有查找您的前缀的表并执行必要的更改。
You can't. What you could do though is write a stored procedure that enumerates all tables looking for your prefix and performs the necessary changes.
由于 ALTER TABLE 语法不允许多个表名,因此您无法执行此操作。您需要依次浏览所有表:
链接:http: //dev.mysql.com/doc/refman/5.0/en/alter-table.html
Given that
ALTER TABLE
syntax doesn't allow multiple table names, you cannot do this. You need to go through all tables in turn:Link: http://dev.mysql.com/doc/refman/5.0/en/alter-table.html
当我想将多个表的引擎从 MyISAM 更改为 InnoDB 时,我没有编写循环,而是制作了完整的数据库转储并在文本编辑器中打开它。在文本编辑器中,我只是将所有 MyISAM 单词更改为 InnoDB。
我知道这不是正确的解决方案,但对我来说,这比为此编写例程更容易。
When I wanted to change multiple table's engine from MyISAM to InnoDB, instead of writing a loop I just made a full DB dump and opened it in a text editor. In the text editor I just simply changed all MyISAM words to InnoDB.
I know that this ain't proper solution but for me it was easier then writing a routine for this.
根据 文档 您只需指定表名称。
You would have to write a loop, according to the documentation you just specify the table name.
我犯了一个愚蠢的错误,将所有 WordPress 表与我的产品表放在一起,幸运的是所有 Wordpress 表都以 wp_ 前缀开头,而我所有其他产品表都没有此 wp_ 前缀。
我创建了另一个名为 wordpress 的数据库,现在我想将所有以 wp_ 开头的表移动到该数据库。
这就是我所做的:
就是这样。
I made a stupid mistake of putting all Wordpress tables with my product tables, fortunately all Wordpress tables start with a wp_ prefix and all my other product tables have no this wp_ prefix.
I created another database named wordpress, now I want to move all tables start with wp_ to that database.
Here is what I did:
That's it.