为什么默认使用MyISAM引擎创建'mysql'数据库而不是InnoDB?

5

我正在使用 MySQL 5.6 版本,默认的 MySQL 引擎是 InnoDB。如果在创建表时不指定引擎,则会使用 InnoDB。

但今天我注意到,默认的 mysql 数据库使用的是 'MyISAM' 而不是 InnoDB。

有什么线索,为什么会这样?

Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
28 rows in set (0.00 sec)

这里是我的cnf文件:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]
init-connect='SET NAMES utf8'
max_connections = 500
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

这是其中一张表的mysqldump:

...

CREATE TABLE `columns_priv` (
  `Host` char(60) COLLATE utf8_bin NOT NULL DEFAULT '',
  `Db` char(64) COLLATE utf8_bin NOT NULL DEFAULT '',
  `User` char(16) COLLATE utf8_bin NOT NULL DEFAULT '',
  `Table_name` char(64) COLLATE utf8_bin NOT NULL DEFAULT '',
  `Column_name` char(64) COLLATE utf8_bin NOT NULL DEFAULT '',
  `Timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `Column_priv` set('Select','Insert','Update','References') CHARACTER SET utf8 NOT NULL DEFAULT '',
  PRIMARY KEY (`Host`,`Db`,`User`,`Table_name`,`Column_name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Column privileges';


mysql> show engines;
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                        | Transactions | XA   | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
| BLACKHOLE          | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| MyISAM             | YES     | MyISAM storage engine                                          | NO           | NO   | NO         |
| FEDERATED          | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
| ARCHIVE            | YES     | Archive storage engine                                         | NO           | NO   | NO         |
| InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                             | NO           | NO   | NO         |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
1个回答

6

14.5.4 将表从 MyISAM 转换为 InnoDB

...

重要提示

不要将 mysql 数据库中的 MySQL 系统表(例如 user 或 host)转换为 InnoDB 类型。这是不受支持的操作。系统表必须始终是 MyISAM 类型。

...


没有检查那些表是否为系统表。好发现。+1 - Rahul Tripathi
谢谢。但是你有什么线索,为什么系统表在MySQL 5.7和5.6的默认引擎是InnoDB时保留在MyISAM格式中吗? - RajSanpui
1
@kingsmasher1:从5.5版本开始,InnoDB是默认引擎,但文档对此并不十分明确:“实现MySQL内部机制的`mysql`和`information_schema`数据库仍然使用MyISAM。特别地,您不能将授权表切换为InnoDB。”请参见14.1.2 InnoDB作为默认的MySQL存储引擎 - wchiquito
@wchiquito,我猜最新版本的MariaDB也适用。我正在使用最新版本的MariaDB,但我注意到mysql中的一些表仍在使用MyISAM。您知道是否有任何内置命令可以处理将这些表迁移到InnoDB吗? - W.M.
1
@W.M.:我不能保证它同样适用于MariaDB,因为MariaDB的文档在这方面不是很明确,请参见《将表从MyISAM转换为InnoDB》(https://mariadb.com/kb/en/library/converting-tables-from-myisam-to-innodb/)。您可以阅读以下错误报告:[允许在MariaDB中使用InnoDB格式的系统表可能导致崩溃](https://jira.mariadb.org/browse/MDEV-10775)。使用MariaDB 10.3.7,我无法重现错误报告中描述的错误。 - wchiquito
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接