What is BIGINT in MySQL: Definition and Usage
BIGINT in MySQL is a data type used to store very large whole numbers, both positive and negative. It can hold values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 when signed, making it ideal for numbers larger than the INT range.How It Works
Think of BIGINT as a very large container for numbers in your database. Just like a small jar can hold a few candies, a regular INT can hold numbers up to about 2 billion. But if you need to store much bigger numbers, like billions of candies, you need a bigger jar — that's where BIGINT comes in.
MySQL uses 8 bytes (64 bits) to store a BIGINT value. This allows it to represent numbers much larger than the 4-byte INT. You can choose to store signed numbers (which include negatives) or unsigned numbers (only zero and positives), which doubles the maximum positive value.
Using BIGINT ensures your database can handle very large counts, IDs, or calculations without running out of space.
Example
This example shows how to create a table with a BIGINT column and insert a large number into it.
CREATE TABLE example_bigint ( id BIGINT PRIMARY KEY, description VARCHAR(100) ); INSERT INTO example_bigint (id, description) VALUES (9223372036854775807, 'Largest signed BIGINT'); SELECT * FROM example_bigint;
When to Use
Use BIGINT when you expect to store numbers larger than what INT can hold. Common cases include:
- Storing large unique IDs, like user IDs in very big systems.
- Counting huge quantities, such as total views or transactions in a popular app.
- Working with timestamps in milliseconds since epoch, which can exceed
INTlimits.
Choosing BIGINT helps avoid errors from number overflow and keeps your data accurate.
Key Points
BIGINTuses 8 bytes of storage.- Signed
BIGINTranges from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. - Unsigned
BIGINTranges from 0 to 18,446,744,073,709,551,615. - Use it for very large integer values beyond
INTlimits. - It is ideal for large IDs, counters, and precise timestamps.
Key Takeaways
BIGINT stores very large whole numbers using 8 bytes.BIGINT when numbers exceed the INT range.BIGINT supports signed and unsigned values for flexibility.