最佳实践Mysql配置在开发中?

时间:2012-04-10 14:02:56

标签: mysql development-environment

我在开发过程中启用了以下功能:

的my.cnf:

[mysqld]
log_slow_queries    = /var/log/mysql/mysql-slow.log
sql_mode            = STRICT_ALL_TABLES

SQL_MODE

STRICT_ALL_TABLES

  

为所有存储引擎启用严格模式。无效的数据值   拒绝。

例如,请考虑以下事项:

CREATE TABLE `posts` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `title` varchar(200) NOT NULL,
    `date` datetime NOT NULL
);
INSERT INTO `posts` (`title`, `date`) VALUES ('Title text', NULL);

如果您使用STRICT_ALL_TABLES sql_mode,则在尝试将NULL值插入NOT NULL列时,mysql 会抛出错误,相反,mysql将根据列的类型插入默认数据。例如对于插入NOT NULL值的日期时间NULL列,mysql会将日期时间值默认为0000-00-00 00-00-00

在某种意义上,严格模式就像打开error_reporting级别并在PHP中显示错误一样,这是开发过程中的最佳实践。

ini_set('error_reporting', -1);
ini_set('display_errors', true);

所以,我想我正在寻找的是,在开发过程中你推荐的配置是什么?为什么?

1 个答案:

答案 0 :(得分:1)

我建议使用以下附加选项:

# creates a innodb file per table instead of having all the tables in a single tablespace file
innodb_file_per_table 

# increase the max allowed packet to a large size for file imports
max_allowed_packet = 32M

# the InnoDB pool size. use up to 80% available RAM for dedicated machines, and as much
# as you can spare for development machines also depending on the size of the databases
# you will be running so that as much of the database as possible fits into memory 
innodb_buffer_pool_size = 512M