【问题标题】:Best practice Mysql configuration in development?开发中的最佳实践Mysql配置?
【发布时间】:2012-04-10 14:02:55
【问题描述】:

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

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_TABLESsql_mode,当尝试将NULL 值插入NOT NULL 列时,mysql 将不会抛出错误,而是 mysql 将插入默认数据,具体取决于列的类型。例如对于 datetime NOT NULL 列,当您插入 NULL 值时,mysql 会将 datetime 值默认为 0000-00-00 00-00-00

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

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

那么,我想我在寻找什么,您在开发过程中推荐的配置是什么?为什么?

【问题讨论】:

  • 您是否有任何具体原因需要更改默认值?
  • @Anil Mathew 否。但例如,将 sql_mode 设置为 strict 可以帮助检测潜在的错误或意外行为。这有点像在 PHP 中设置display_errors=1 & error_reporting(-1)

标签: mysql development-environment


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多