Character sets and data types

Character sets and data types

A character set

  • Character set is a standard specification for the SQL statement coding style, if there is no uniform set of characters, SQL statements in the use of the process will be chaos.
  • Discover all character sets: show charset;
  • Just beginning to build a database character set encoding format is latin1, mainstream database character set currently used in China is utf8 or utf8mb4, a small amount will be used gbk.
  • utf8 and utf8mb4 difference:
    • utf8: a Chinese occupies 3 bytes, data can not be stored in this expression emoji character set
    • utf8mb4: a Chinese 4 bytes, this character set data may be stored emoji expression, and contains the plain utf8 mb4

    Recommend direct selection utf8mb4 when the database is created.

Second, validation rules / collation (collation)

  • View all collation: show collation;
  • utf8mb4_general_ci: not case sensitive
  • utf8mb4_bin: case sensitive

Depending on the scene to select the collation for ah

Third, the data type

  • Digital Type:
    • tinyint: minimum integer type, in the range of 0 to 256
    • smallint: smaller integer type, the range of -2 15 to 2 15
    • int type: conventional integer type, the range of -2 32 to 2 32-1
  • String
    • Data type most used in the production of
    • category:
      • char (100): The fixed-length data type, data length 100 indicates, regardless of how long the length of a string, the storage space 100 is allocated immediately characters long, are not filled with spaces to fill the space
      • varchar (num): variable length data type, num indicates the length of data. Each time before storing the data must first determine what the length of the string, on-demand disk space . We will apply for a single string length of the space to store the length of the string (less than 255),
        if more than two string lengths take up storage space.

      How to select these two types of data: data when the data length is less than 255, and selects a fixed-length char (100), if the data length is greater than 255 or a variable length is selected varchar (num)

      • enum (enumeration)
  • time
    • datatime: year, month, day, hour
      • Range: 1000-01-01 00:00:00 9999-12-3123: 59: 59.999999
      • What time zone is set to start has been fixed and will not change
    • timestamp: When the year, month, day, hour
      • Scope: 1970-01-01 00:00:00 2038-01-1903: 14: 07.999999
      • Will automatically go according to the time zone
  • Binary

Guess you like

Origin www.cnblogs.com/ddzc/p/12557533.html