InnoDB 中文参考手册 --- 3 建立一个 InnoDB 数据库

参考|参考手册|数据|数据库|中文

InnoDB 中文参考手册 --- 犬犬(心帆)翻译 3 建立一个 InnoDB 数据库
假设你已经安装了 MySQL 并且已经修改了 my.cnf 包含了必要的 InnoDB 参数设置 。在启动 MySQL 之前必须检查为InnoDB 指定的数据与日志文件路径是否存在以及在 这些目录上有足够的权限。InnoDB 不会自己建立目录,只能建立文件。同时检查是否有足够的磁盘空间存放数据与日志文件。

当创建一个 InnoDB 数据库时最好以命令行方式来运行 MySQL 服务 mysqld ,而不是从 safe_mysqld 或 Windows 服务。当从命令行方式运行服务时可以看到建立过程。

现在运行 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

现在一个新的 InnoDB 数据库被建立了。你可以通过 MySQL 的客户端程序(比如 mysql)连接 MySQL 服务器。当通过 mysqladmin shutdown 关闭 MySQL 服务时,InnoDB 输出如下所示:

020204 23:34:45 mysqld: Normal shutdown 020204 23:34:45 InnoDB: Starting shutdown... 020204 23:34:47 InnoDB: Shutdown completed 020204 23:34:47 mysqld: Shutdown Complete

现在你可以看到数据文件与日志文件已被建立。在日志文件目录下也会包含一个句为 ib_arch_log_0000000000 的小文件。这是当 InnoDB 的日志存档(log archiving)开关关闭后,数据库建立后形成的文件。 当 MySQL 再次启动时,屏幕显示所下所示:

heikki@donna:~/mysql-3.23.48/sql> mysqld 020204 23:34:27 InnoDB: Started mysqld: ready for connections
3.1 在建立数据库时可能发生的几个错误
如果 InnoDB 显示一个文件操作的操作系统错误,请查看第 13.2 节 错误代码的含义。常见的错误如下: 没有创建 InnoDB 数据或日志文件目录。 mysqld 在那些目录下没有建立文件的权限。 mysqld 没有权限读取 my.cnf 或 my.ini 文件,因而无法配置所指定的选项。 磁盘空间已满或超过磁盘配额。 建立了一个与数据文件同名的子目录。 innodb_data_home_dir 或 innodb_data_file_path 中设置语法出错。
如果在 InnoDB 数据库创建时发生了一个错误,你必须删除所有 InnoDB 创建的文件。 这就意味着所有的数据文件、所有的日志文件、日志存档文件,如果你已经建立了一些 InnoDB 表,必须删除 MySQL 数据目录下相应的 “.frm”文件。然后可以再尝试建立 InnoDB 数据库。最好以命令行方式启动 MySQL 服务,从而可以看到建立过程。
3.2 关闭 MySQL 服务
通常在关闭计算机之前你必须先关闭数据库服务。在命令行方式下输入 mysqladmin shutdown 可以以服务。

在 Windows NT 和 2000 下可以将 MySQL 服务安装为 Windows 系统服务。这样在计算机启动时 MySQL 服务会自动启动或在命令行方式下输入 MS-DOS 命令 NET START MySQL 或从操作系统的服务菜单中启动。

如果以系统服务方式运行 MySQL,可以通过 MS-DOS的 NET STOP MySQL 命令或操作系统的服务菜单中关闭服务。你同样可以让操作系统退出前自动关闭 MySQL。在低于 MySQL 3.23.47 版本的系统中,Windows 操作系统仅仅只等待一段时间让 InnoDB 完全关闭,如果限止时间超过将杀死数据服务线程。那在下一次 InnoDB 启动不得不不进行一个崩溃修复。从 MySQL version 3.23.48 开始,操作系统将等待 InnoDB 完全关闭。

如果你的操作系统没有为 InnoDB 完全关闭提供足够的时间,最安全的办法就是在 MS-DOS 命令行下运行 MySQL 服务,并用 mysqladmin shutdown 关闭服务。

在 Windows NT (但 Windows 2000 无些问题)下,当计算机关闭时,有一个可能发生的问题就是 Windows NT 默认等待 20 秒以关闭一个服务,服务未能关闭将杀死服务线程。可以通过运行注册表编辑器 \winnt ystem32\regedt32.exe 来修改 HKEY_LOCAL_MACHINE YSTEM\CurrentControlSet\Control 中的 WaitToKillServiceTimeout 键值以增加这个默认值。以毫秒为单位给定一个更大的值。
 

时间: 2024-08-31 02:26:42

InnoDB 中文参考手册 --- 3 建立一个 InnoDB 数据库的相关文章

InnoDB 中文参考手册 --- 4 建立 InnoDB 表

参考|参考手册|中文 4 建立 InnoDB 表假设你已以 mysql test 命令方式运行了 MySQL 客户端程序.为了建立一个 InnoDB 格式的表你必须在 SQL 命令中指定 TYPE = InnoDB : CREATE TABLE CUSTOMER (A INT, B CHAR (20), INDEX (A)) TYPE = InnoDB; 这个 SQL 命令将在 my.cnf 中设定的 InnoDB 数据文件中创建一个表和一个列 A 的索引,同时将在 MySQL 数据目录下的 t

InnoDB 中文参考手册 --- 5 添加与移除 InnoDB 数据和日志文件

参考|参考手册|数据|中文 InnoDB 中文参考手册 --- 犬犬(心帆)翻译 5 添加与移除 InnoDB 数据和日志文件为了添加一个数据文件到表空间中,首先要关闭 MySQL 数据库,编辑 my.cnf 文件,在 innodb_data_file_path 中添加一个新文件,然后再重新启动服务. 如果,最后一个文件以关键字 autoextend 来描述,那么编辑 my.cnf 的过程如下所示.必须检查最后一个文件的尺寸,并使它向下接近于 1024 * 1024 bytes (= 1 MB)

InnoDB 中文参考手册 --- 目录

参考|参考手册|中文 InnoDB 中文参考手册 --- 犬犬(心帆)翻译 InnoDB home InnoDB Engine in MySQL-Max-3.23.56/MySQL-4.0.12The Up-to-Date Reference Manual of InnoDB Updated April 21, 2003: Added notes to section 4.3 that a self-referential ON UPDATE CASCADE and SET NULL conve

InnoDB 中文参考手册 --- InnoDB Tables 概述

参考|参考手册|中文 InnoDB 中文参考手册 --- 犬犬(心帆)翻译 1 InnoDB Tables 概述 InnoDB 给 MySQL 提供了具有事务(commit).回滚(rollback)和崩溃修复能力(crash recovery capabilities)的事务安全(transaction-safe (ACID compliant))型表.InnoDB 提供了行锁(locking on row level),提供与 Oracle 类型一致的不加锁读取(non-locking re

InnoDB 中文参考手册 --- 2 InnoDB 启动选项

参考|参考手册|中文 InnoDB 中文参考手册 --- 犬犬(心帆)翻译 2 InnoDB 启动选项为了在 MySQL-Max-3.23 中使用 InnoDB 表,你必须在配置文件'my.cnf'或'my.ini'(WINDOWS系统)中的 [mysqld] 区中详细指定配置参数. 作为最小设置,在 3.23 中你必须在 innodb_data_file_path 上指定数据文件名能及大小.如果在'my.cnf'中没有指定innodb_data_home_dir,系统将在 MySQL 的 da

InnoDB 中文参考手册 --- 6 备份和恢复 InnoDB 数据库

备份|参考|参考手册|恢复|数据|数据库|中文 InnoDB 中文参考手册 --- 犬犬(心帆)翻译 6 备份和恢复 InnoDB 数据库安全的数据库管理就是使用正规的数据备份. InnoDB Hot Backup 是一个在线备份工具,你可以在 InnoDB 数据库运行时使用它来实现在线备份.InnoDB Hot Backup 不需要你关闭你的服务器也不需要加任何锁或影响其它普通的数据操作.InnoDB Hot Backup 是一个非免费的附加工具,它的费用为每 MySQL 服务器每年 400

InnoDB 中文参考手册 --- 8 InnoDB 事务模式与锁定

参考|参考手册|中文 InnoDB 中文参考手册 --- 犬犬(心帆)翻译 8 InnoDB 事务模式与锁定在 InnoDB 事务处理模式中, the goal has been to combine the best properties of a multiversioning database to traditional two-phase locking. InnoDB 进行行级的锁定,并以与 Oracle 非锁定读取(non-locking)类似的方式读取数据. InnoDB 中的锁

InnoDB 中文参考手册 --- 9 性能调整技巧

参考|参考手册|技巧|性能|中文 InnoDB 中文参考手册 --- 犬犬(心帆)翻译 9 性能调整技巧(Performance tuning tips)1. 如果 Unix top 或 Windows 任务管理器(Task Manager) 显示服务的 CPU 占用率小于 70%,(shows that the CPU usage percentage with your workload is less than 70 %,)你的系统瓶颈可能在磁盘读写上.或许你提交了大量的事务,或者是缓冲池

InnoDB 中文参考手册 --- 12 文件空间管理和磁盘 I/O

参考|参考手册|中文 InnoDB 中文参考手册 --- 犬犬(心帆)翻译 12 文件空间管理和磁盘 I/O12.1 磁盘 I/O 和 raw devicesInnoDB 使用模拟的异步(simulated asynchronous)的磁盘 I/O来构建 InnoDB:InnoDB 建立许多的 i/o 线程来处理 i/o 操作,就如同 read-ahead 一样. 从 3.23.40b 开始,InnoDB 使用一种被称为"双写 (doublewrite)" 的新颖的文件转储清除(flu