我在开发过程中启用了以下功能:
我的.cnf:
[mysqld]
log_slow_queries = /var/log/mysql/mysql-slow.log
sql_mode = STRICT_ALL_TABLES
SQL_MODE
STRICT_ALL_TABLES
Enable strict mode for all storage engines. Invalid data values are rejected.
例如,考虑以下内容:
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
值时,mysql 不会抛出一个错误到 NOT NULL
列中,mysql 将根据列的类型插入默认数据。例如对于日期时间 NOT NULL
列,当您插入 NULL
值时,mysql 会将日期时间值默认为 0000-00-00 00-00-00
.
从某种意义上说,严格模式就像在 PHP 中调高 error_reporting 级别并显示错误,这是开发过程中的最佳实践。
ini_set('error_reporting', -1);
ini_set('display_errors', true);
那么,我想我正在寻找的是您在开发过程中推荐的配置是什么,为什么?
最佳答案
我会推荐以下附加选项:
# 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
关于mysql - 开发中的最佳实践Mysql配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10090293/