简体   繁体   English

仅在MyISAM表中更改mysql中的表

[英]Alter table in mysql only for MyISAM tables

I am trying to convert all mysql MyISAM tables to InnoDB without pick the already in InnoDB. 我试图将所有mysql MyISAM表转换为InnoDB,而不选择InnoDB中已经存在的表。

I have 6734 rows (tables in MyISAM format) using this query: 我使用此查询有6734行(MyISAM格式的表):

SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE engine = 'MyISAM';

And I have 11218 rows (tables in InnoDB format) using this query: 我使用此查询有11218行(InnoDB格式的表):

SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE engine = 'InnoDB';

So I want connect each result of tables in MyISAM for pass only as subquery: 所以我想连接MyISAM中表的每个结果以仅作为子查询传递:

ALTER TABLE table_name ENGINE = InnoDB;

How this can be achieved? 如何做到这一点? select subquery? 选择子查询? My purpose is avoid to process the already converted to innodb because it will take a lot more time if I make a script as the following: 我的目的是避免处理已转换为innodb的内容,因为如果按照以下方式编写脚本,则会花费更多时间:

for db in `echo "show databases"| mysql`;
do
echo $db

echo 'SHOW TABLES;' \
 | mysql -D $db \
 | awk '!/^Tables_in_/ {print "ALTER TABLE `"$0"` ENGINE = InnoDB;"}' \
 | column -t \
 | mysql -D $db
echo 'finish';
done;

You can direct create the ALTER statements in SQL. 您可以直接在SQL中创建ALTER语句。 if you have more SCHEMAS to ignore you can add them in the IN clause. 如果还有更多的SCHEMAS要忽略,则可以在IN子句中添加它们。

SELECT
  CONCAT ('ALTER TABLE `',TABLE_SCHEMA, '`.`' ,TABLE_NAME,'` ENGINE = InnoDB;') as newsql
FROM INFORMATION_SCHEMA.TABLES 
WHERE TABLE_TYPE = 'BASE TABLE'
  AND TABLE_SCHEMA NOT IN ('mysql')
  AND `ENGINE` = 'MYISAM';

To use with shell: 与外壳一起使用:

echo "SELECT CONCAT ('ALTER TABLE \`',TABLE_SCHEMA, '\`.\`' ,TABLE_NAME,'\` ENGINE = InnoDB;')  FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA NOT IN ('mysql') AND \`ENGINE\` = 'MYISAM';" |mysql --skip-column-names |mysql 

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

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