配置好 my.cnf 或者 my.ini 的参数之后,就可以启动 MySQL 建立 InnoDB 了,第一次建立之前,建议你手工启动,这样你就可以看到 InnoDB 的建立过程: heikki@donna:~/mysql-3.23.48/sql> mysqld 020204 23:17:12 InnoDB: The first specified data file /dr2/tmp/heikki/data/ibdata1 did not exist: InnoDB: a new database to be created! InnoDB: Setting file /dr2/tmp/heikki/data/ibdata1 size to 20 MB InnoDB: Database physically writes the file full: wait... 020204 23:17:16 InnoDB: Data file /dr2/tmp/heikki/data/ibdata2 did not exist: new to be created InnoDB: Setting file /dr2/tmp/heikki/data/ibdata2 size to 200 MB InnoDB: Database physically writes the file full: wait... 020204 23:17:41 InnoDB: Data file /dr2/tmp/heikki/data/ibdata3 did not exist: new to be created InnoDB: Setting file /dr2/tmp/heikki/data/ibdata3 size to 1000 MB InnoDB: Database physically writes the file full: wait... 020204 23:21:37 InnoDB: Log file ./ib_logfile0 did not exist: new to be created InnoDB: Setting log file ./ib_logfile0 size to 10 MB InnoDB: Database physically writes the file full: wait... 020204 23:21:39 InnoDB: Log file ./ib_logfile1 did not exist: new to be created InnoDB: Setting log file ./ib_logfile1 size to 10 MB InnoDB: Database physically writes the file full: wait... 020204 23:21:41 InnoDB: Log file ./ib_logfile2 did not exist: new to be created InnoDB: Setting log file ./ib_logfile2 size to 10 MB InnoDB: Database physically writes the file full: wait... InnoDB: Doublewrite buffer not found: creating new InnoDB: Doublewrite buffer created InnoDB: Creating foreign key constraint system tables InnoDB: Foreign key constraint system tables created 020204 23:21:45 InnoDB: Started mysqld: ready for connections
目前任何 ALTER TABLE 操作都会删除外键约束,因此,建议采用 DROP TABLE 然后 CREATE TABLE 来修改 schema。因为 ALTER TABLE 在内部使用 RENAME TABLE 操作,这样就能混淆外键的引用,同样的 CREATE INDEX 也是作为 ALTER TABLE 来处理的,也不能用于外键约束的表。
InnoDB 允许你 drop 任何表,即使这样会打破外键,这样操作的结果就是约束也被 drop 了。
查看表 T 中的外键约束状态:
SHOW TABLE STATUS FROM yourdatabasename LIKE 'T'
InnoDB 还不支持 CASCADE ON DELETE 或者其特殊的约束选项。(我们知道 Oracle 里面有这个东东了)