🌳🌳🌳个人博客:Harvey的个人博客 🌲🌲🌲
1:空值('')是不占用空间的
2: MySQL中的NULL其实是占用空间的。官方文档说明:
“NULL columns require additional space in the row to record whether their values are NULL. For MyISAM tables, each NULL column takes one bit extra, rounded up to the nearest byte.”
所以 mysql设计表时 建议不要用default NULL
string类型 建议用 ''" 或者 Empty String
int类型 建议默认给 0
另外一点,从不同的项目开发去分析这个问题:
以前单纯做web网页端,对这个默认值设定问题选用null 还是empty string。但是后来在另外一个团队开发app的时候,这个null和empty string的问题就尤为突出,因为我是用php做接口开发,如果一旦出现null的数据类型,没有处理直接返回去前端,那么无论是ios还是Android端,如果没有处理好这个空的判断,要么就直接输出null,要么程序直接报错。所有建议设计数据库的时候默认值尽量少用null.