> For the complete documentation index, see [llms.txt](https://bohans.gitbook.io/ji-chu/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bohans.gitbook.io/ji-chu/mysql/sql-you-hua/schema-she-ji/xuan-ze-shu-ju-lei-xing/zheng-shu-lei-xing.md).

# 整数类型

如果存储整数，可以使用这几种整数类型：<mark style="color:blue;">**TINYINT**</mark>、<mark style="color:blue;">**SMALLINT**</mark>、<mark style="color:blue;">**MEDIUMINT**</mark>、<mark style="color:blue;">**INT**</mark> 或 <mark style="color:blue;">**BIGINT**</mark>。它们分别使用 <mark style="color:blue;">**8**</mark>、<mark style="color:blue;">**16**</mark>、<mark style="color:blue;">**24**</mark>、<mark style="color:blue;">**32**</mark> 和 <mark style="color:blue;">**64**</mark> 位存储空间。**可以存储的值的范围从 -2^(N-1) 到 2^(N-1)-1**，其中 N 是存储空间的位数。

| 类型                                             | 长度 |
| ---------------------------------------------- | -- |
| <mark style="color:blue;">**TINYINT**</mark>   | 8  |
| <mark style="color:blue;">**SMALLINT**</mark>  | 16 |
| <mark style="color:blue;">**MEDIUMINT**</mark> | 24 |
| <mark style="color:blue;">**INT**</mark>       | 32 |
| <mark style="color:blue;">**BIGINT**</mark>    | 64 |

整数类型有可选的 <mark style="color:blue;">**UNSIGNED**</mark> 属性，表示<mark style="color:blue;">**不允许负值**</mark>，这大致可以使正数的上限提高一倍。例如，TINYINT UNSIGNED 可以存储的值的范围是 0～255，而 TINYINT 的值的存储范围是 -128～127。

{% hint style="warning" %}
**对于整数类型的选择只是决定了 MySQL 在内存和磁盘中保存数据的方式。**

<mark style="color:orange;">**整数计算通常使用 64 位的 BIGINT 整数。**</mark>（一些聚合函数是例外，它们使用 DECIMAL 或 DOUBLE 进行计算。）
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bohans.gitbook.io/ji-chu/mysql/sql-you-hua/schema-she-ji/xuan-ze-shu-ju-lei-xing/zheng-shu-lei-xing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
