最佳实践MySQL数据类型列表 [英] List of Best Practice MySQL Data Types

查看:68
本文介绍了最佳实践MySQL数据类型列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有常见应用程序的最佳实践MySQL数据类型列表.例如,列表应包含ID,IP地址,电子邮件,主题,摘要,描述内容,URL,日期(时间戳和人类可读),地理位置,媒体高度,媒体宽度,媒体持续时间,等等

Is there a list of best practice MySQL data types for common applications. For example, the list would contain the best data type and size for id, ip address, email, subject, summary, description content, url, date (timestamp and human readable), geo points, media height, media width, media duration, etc

谢谢!

推荐答案

我什么都不知道,所以让我们开始吧!

i don't know of any, so let's start one!

数字ID/自动递增主键:使用无符号整数.不要使用0作为值.并记住各种大小的最大值,即在mediumint提供的1600万个就足够的情况下,如果您不需要40亿个值,请不要使用int.

numeric ID/auto_increment primary keys: use an unsigned integer. do not use 0 as a value. and keep in mind the maximum value of of the various sizes, i.e. don't use int if you don't need 4 billion values when the 16 million offered by mediumint will suffice.

日期:除非您特别需要不在mysql的DATE和TIME类型支持的范围内的日期/时间,否则请使用它们!如果改用Unix时间戳,则必须将它们转换为使用内置的日期和时间函数.如果您的应用需要Unix时间戳,则始终可以在出局时使用unix_timestamp()转换标准日期和时间数据类型.

dates: unless you specifically need dates/times that are outside the supported range of mysql's DATE and TIME types, use them! if you instead use unix timestamps, you have to convert them to use the built-in date and time functions. if your app needs unix timestamps, you can always convert the standard date and time data types on the way out using unix_timestamp().

IP地址:使用

ip addresses: use inet_aton() and inet_ntoa() since it easily compacts an ip address in to 4 bytes and gives you the ability to do range searches that utilize indexes.

这篇关于最佳实践MySQL数据类型列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆