MySQL 将某个数据库下的所有表的存储引擎修改为 InnoDB 类型语句

2019-06-26T10:41:00

如何将mysql数据库中的MyISAM类型表更改为InnoDB类型的表

改单个表

ALTER TABLE TABLENAME ENGINE=InnoDB;
ALTER TABLE TABLENAME ENGINE=MyISAM;

改多个表

#修改为InnoDB
SELECT CONCAT( 'ALTER TABLE ', TABLE_NAME, ' ENGINE=InnoDB;' )
FROM information_schema.tables
WHERE table_schema = 'DBNAME'
LIMIT 0 , 10000;
 
#修改为MyISAM
SELECT CONCAT( 'ALTER TABLE ', TABLE_NAME, ' ENGINE=MyISAM;' )
FROM information_schema.tables
WHERE table_schema = 'DBNAME'
LIMIT 0 , 10000;

使用说明:

  1. 将以上SQL语句中的 DBNAME 替换成需要修改的数据库名称。
  2. 执行SQL,这个时候还没有修改,只是给了一个查询结果。
  3. 将查询结果复制,去掉前后的引号,然后执行。

批量修改mysql数据库字符集

ALTER DATABASE DBNAME DEFAULT CHARACTER SET='utf8';

mysql数据库表字段乱码,连接数据库时设置正确的编码即可

mysql_query('set names utf8');

zencart示例

Mysql修改表、字段、库的字符集

ALTER DATABASE `zc139` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

ALTER TABLE `news_articles` ENGINE=INNODB;
ALTER TABLE `news_articles_text` ENGINE=INNODB;
ALTER TABLE `news_authors` ENGINE=INNODB;
ALTER TABLE `news_comments` ENGINE=INNODB;
ALTER TABLE `news_comments_description` ENGINE=INNODB;
ALTER TABLE `popular_searches` ENGINE=INNODB;
ALTER TABLE `un_products_to_wishlists` ENGINE=INNODB;
ALTER TABLE `un_wishlists` ENGINE=INNODB;


ALTER TABLE `news_articles` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `news_articles_text` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `news_authors` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `news_comments` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `news_comments_description` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `popular_searches` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `un_products_to_wishlists` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `un_wishlists` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

转自:小鱼阁工作室 - cnblogs

当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »