MySQL 菜鸟笔记

  • TINYINT(M),INT(M) 等,其中 M 不会影响数据范围,存储的值如下表(官方表格链接)
    data_types.png

    M 的作用如下(详情看官网介绍)

MySQL supports an extension for optionally specifying the display width of integer data types in parentheses following the base keyword for the type. For example, INT(4) specifies an INT with a display width of four digits.

When used in conjunction with the optional (nonstandard) ZEROFILL attribute, the default padding of spaces is replaced with zeros. For example, for a column declared as INT(4) ZEROFILL, a value of 5 is retrieved as 0005.

  • 编码请使用 utf8mb4(官网编码相关介绍)

The utf8mb3 character set is deprecated and will be removed in a future MySQL release. Please use utf8mb4 instead. Although utf8 is currently an alias for utf8mb3, at some point utf8 will become a reference to utf8mb4. To avoid ambiguity about the meaning of utf8, consider specifying utf8mb4 explicitly for character set references instead of utf8.

  • MySQL 关键词
SELECT * FROM INFORMATION_SCHEMA.KEYWORDS;
https://dev.mysql.com/doc/refman/8.0/en/keywords.html
  • 查看表的大小
SELECT DATA_LENGTH, INDEX_LENGTH FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'database' AND TABLE_NAME = 'table name';
https://dev.mysql.com/doc/mysql-infoschema-excerpt/8.0/en/information-schema-tables-table.html
DATA_LENGTH, INDEX_LENGTH 单位为 byte
  • 查看表分区情况
// 查看分区情况
SELECT * FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA = 'database' AND TABLE_NAME = 'table name';
// 移除分区,保留数据
ALTER TABLE table name REMOVE PARTITIONING;

你可能感兴趣的:(MySQL 菜鸟笔记)