Home  >  Article  >  Database  >  mysql field type selection method

mysql field type selection method

小云云
小云云Original
2018-03-17 17:12:161685browse


This article mainly shares with you the method of selecting the mysql field type. Decibel shares with you the integer and time types (choose the accurate type), hoping to help everyone.

Occupy as little storage space as possible

Integer type

mysql field type selection method

Time type (choose the accurate Type)

##year()Yeardate()年月日##timestamp()It is best to integrate data with a fixed length
Type Meaning
time() Hours, minutes and seconds
datetime() Year, month, day Hours, minutes and seconds
Timestamp( Number of seconds elapsed from 1970-1-1 to now)

char (number of characters)

    Fixed length, fast running speed, occupying more storage
  • Length: 255 character limit
  • varchar( Number of bytes)

    The length is not fixed, and the content is relatively small and requires position operation. This type should reserve 1-2 bytes to save the length of the current data
  • Length: 65535 bytes limit
  • Storage Chinese characters, such as character set utf8 (each Chinese character occupies 3 bytes), can store up to 65535/3-2 Bytes
  • Information is best stored as integer
 时间信息可以存储为整型的(时间戳)
set集合类型 多选:set(‘篮球’,’足球’,’棒球’,’乒乓球’);enum枚举类型 单选: enum(‘男’,’女’,’保密’);
推荐使用set和enum类型,内部会通过整型信息参数具体计算、运行。
ip地址也可以变为整型信息进行存储(mysql内部有算法,把ip变为数字):
mysql: inet_aton(ip)   inet_ntoa(数字)php:      ip2long(ip)       long2ip(数字)

Summary:

Principle of field type selection: small space occupied, The data length is preferably fixed and the data content is preferably of integer type

The above is the detailed content of mysql field type selection method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn