本文介绍一些在使用MySQL时经常遇到错误案例以及解决办法。
- InnoDB: Fatal error: cannot allocate memory for the buffer pool
[codesyntax lang="ini"]
160111 11:13:00 InnoDB: Initializing buffer pool, size = 512.0M
InnoDB: mmap(549453824 bytes) failed; errno 12
160111 11:13:00 InnoDB: Completed initialization of buffer pool
160111 11:13:00 InnoDB: Fatal error: cannot allocate memory for the buffer pool
160111 11:13:00 [ERROR] Plugin 'InnoDB' init function returned error.
160111 11:13:00 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
160111 11:13:00 [ERROR] Unknown/unsupported storage engine: InnoDB
160111 11:13:00 [ERROR] Aborting
160111 11:13:00 [Note] /usr/sbin/mysqld: Shutdown complete
[/codesyntax] 如果启动MySQL失败,在日志文件(/var/log/mysql/error.log)中看到有上面的错误的话,可能是因为缓存设置的过大了——一般不能超过操作系统的内存大小。修改办法如下: 找到MySQL的配置文件my.conf,然后修改mysqld节点下的如下配置(没有的话添加即可): innodb_buffer_pool_size = 64M
- Checking for tables which need an upgrade, are corrupt or were not closed cleanly.
- /etc/init.d/mysql: fork: Cannot allocate memory
- ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails
在对设置有外键的表上执行delete语句时,就有可能发生这种错误。要了解这个错误的原因,首先要了解下面的内容: 在添加外键时,可以设置删除时的动作(RESTRICT、CASCADE、NO ACTION、SET NULL)。如果你设置的值为RESTRICT的话就会发生上面的错误。同样,在执行update操作时,也可以这样设置。
- ERROR 1005 (HY000): Can't create table (errno: 150)