简体   繁体   English

如何将所有 InnoDB 表转换为 MyISAM?

[英]How can I convert all InnoDB Tables to MyISAM?

Hi guys I'm searching for a methode (sql code) with which I can convert in my WordpressDB all InnoDBs to MyISAM .大家好,我正在寻找一种方法(sql 代码),我可以使用它在我的 WordpressDB 中将所有 InnoDBs 转换为 MyISAM 。

My code since now is:从现在开始我的代码是:

SELECT CONCAT('ALTER TABLE ', TABLE_SCHEMA, '.', TABLE_NAME,' ENGINE=MyISAM;') FROM Information_schema.TABLES WHERE ENGINE = 'InnoDB'

This gives me back:这让我回来了:

ALTER TABLE db.wp_comments ENGINE=MyISAM;
ALTER TABLE db.wp_links ENGINE=MyISAM;
ALTER TABLE db.wp_options ENGINE=MyISAM;
ALTER TABLE db.wp_postmeta ENGINE=MyISAM;
ALTER TABLE db.wp_posts ENGINE=MyISAM;
ALTER TABLE db.wp_term_relationships ENGINE=MyISAM;
ALTER TABLE db.wp_term_taxonomy ENGINE=MyISAM;
ALTER TABLE db.wp_termmeta ENGINE=MyISAM;
ALTER TABLE db.wp_terms ENGINE=MyISAM;
ALTER TABLE db.wp_usermeta ENGINE=MyISAM;
ALTER TABLE db.wp_users ENGINE=MyISAM;

Now I want to execute all of this rows at once I want to save all the results in one variable and execute them.现在我想一次执行所有这些行我想将所有结果保存在一个变量中并执行它们。 But a sql variable can just save one row... How do I execute now all of this rows at once with just plain sql code?但是一个 sql 变量只能保存一行......我现在如何只用普通的 sql 代码一次执行所有这些行?

Thanks in advance提前致谢

PS: can I use "Update" to solve this problem as update may can update the engine to MyISAM? PS:我可以使用“更新”来解决这个问题,因为更新可以将引擎更新到 MyISAM 吗?

Just tested another (simple ?) way, and worked for me.刚刚测试了另一种(简单?)方式,并为我工作。

Just export your DB as .sql file, edit-it with gedit or notepad;只需将您的数据库导出为 .sql 文件,使用 gedit 或记事本进行编辑;

Replace 'ENGINE=INNODB' with 'ENGINE=MyISAM' and Save the file edited将 'ENGINE=INNODB' 替换为 'ENGINE=MyISAM' 并保存编辑的文件

Number or replacement done should be the number of your tables完成的数量或替换应该是您的表的数量

Import it to MySQL (phpMyAdmin or command line)将其导入 MySQL(phpMyAdmin 或命令行)

And Voila !瞧!

Take backup of Mysql database.备份 Mysql 数据库。 Run this sql query via terminal for the database which you wish to convert into MYISAM.通过终端为您希望转换为 MISAM 的数据库运行此 sql 查询。

mysql -h databasehostname -u username -p -e "SELECT concat('ALTER TABLE ', TABLE_NAME,' ENGINE=MYISAM;') FROM Information_schema.TABLES WHERE TABLE_SCHEMA = 'db_name' AND ENGINE = 'InnoDB' AND TABLE_TYPE = 'BASE TABLE'" | tail -n+2 >> alter.sql

Note: Change 'db_name' with your actual database name注意:使用您的实际数据库名称更改“db_name”

Note: You only need the -h flag if your database is not local to the machine you are logged in to the terminal of注意:如果您的数据库不是您登录到终端的计算机的本地数据库,则仅需要 -h 标志

Import that alter.sql file into INNODB database将该 alter.sql 文件导入 INNODB 数据库

mysql -h databasehostname -u username -p databasename < alter.sql

Why?为什么? MyISAM is going away in the next release of MySQL. MyISAM 将在 MySQL 的下一个版本中消失。 MyISAM is less efficient, less robust, etc, etc. MyISAM 效率较低、鲁棒性较差等。

Here's how to do the ALTERs :以下是ALTERs的操作方法:

  1. Generate alter statements into a file or the screen.将更改语句生成到文件或屏幕中。 (You have done that.) (你已经做到了。)

  2. Copy them (or feed them) into the mysql commandline tool.将它们复制(或输入)到 mysql 命令行工具中。

  3. Go get a coffee.去喝杯咖啡。

But watch out for errors.但要注意错误。

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

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