ITEEDU

15.2.5 . 创建InnoDB表空间

15.2.5.1. 处理InnoDB初始化问题

假设你已经安装了MySQL,并且已经编辑了选项文件,使得它包含必要的InnoDB配置参数。在启动MySQL之前,你应该验证你为InnoDB数据文件和日志文件指定的目录是否存在,并且MySQL有访问这些目录的权限。InnoDB不能创建目录,只能创建文件。也检查你有足够的空间来放数据和日志文件。

当创建InnoDB数据库时,最好从命令提示符运行MySQL服务器mysqld, 而不要从mysqld_safe包装或作为Windows的服务来运行。当你从命令提示符运行,你可看见mysqld打印什么以及发生了什么。在Unix上,只需要调用mysqld。在Windows上,使用--console选项。

当在选项文件里初始地配置InnoDB后,开始启动MySQL服务器之时,InnoDB创建一个数据文件和日志文件。InnoDB打印如下一些东西:

InnoDB: The first specified datafile /home/heikki/data/ibdata1

did not exist:

InnoDB: a new database to be created!

InnoDB: Setting file /home/heikki/data/ibdata1 size to 134217728

InnoDB: Database physically writes the file full: wait...

InnoDB: datafile /home/heikki/data/ibdata2 did not exist:

new to be created

InnoDB: Setting file /home/heikki/data/ibdata2 size to 262144000

InnoDB: Database physically writes the file full: wait...

InnoDB: Log file /home/heikki/data/logs/ib_logfile0 did not exist:

new to be created

InnoDB: Setting log file /home/heikki/data/logs/ib_logfile0 size

to 5242880

InnoDB: Log file /home/heikki/data/logs/ib_logfile1 did not exist:

new to be created

InnoDB: Setting log file /home/heikki/data/logs/ib_logfile1 size

to 5242880

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

InnoDB: Started

mysqld: ready for connections

一个新的InnoDB数据库被创建了。你可以用mysql这样通常的MySQL客户端程序连接到MySQL服务器。当你用mysqladmin shutdown关闭MySQL服务器之时,输出类似如下:

010321 18:33:34  mysqld: Normal shutdown

010321 18:33:34  mysqld: Shutdown Complete

InnoDB: Starting shutdown...

InnoDB: Shutdown completed

你可以看数据文件和日志文件,并且你可以看见文件被创建。日志目录也包含一个名为ib_arch_log_0000000000的小文件。这个文件是数据库被创建的结果,数据库被创建之后InnoDB切断日志归档。当MySQL再次启动之时,数据文件&日志文件已经被创建,所以输出更简洁:

InnoDB: Started

mysqld: ready for connections

你可以添加innodb_file_per_table选项到my.cnf文件,并且让InnoDB存储每一个表到MySQL数据库目录里自己的.ibd文件。请参阅15.2.6.6节,“使用Per-Table表空间”