MySQL Data Types: Reference Table and Java Mapping
Run INSERT INTO people (age) VALUES (300); against a column declared as age TINYINT, and MySQL 8 answers with ERROR 1264: Out of range value for column 'age'. On a server without strict mode the same statement “succeeds” — and the table silently stores 127. The column type decides which values the database accepts, clips or rejects.
A MySQL data type is a property of a table column that defines which values the column can hold, how many bytes they take and how they are compared. You choose a data type for every column when you create a table. MySQL data types fall into groups: integers, fractional numbers, strings, binary data, date and time, plus special types — ENUM, SET and JSON.
MySQL Data Types at a Glance
Six data types cover most MySQL tables: INT or BIGINT for identifiers and counters, DECIMAL for money, VARCHAR for short strings, TEXT for long text, and DATE or DATETIME for dates. The remaining types exist for special cases.
| Group | Types | Used for | Example column |
|---|---|---|---|
| Integers | TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT | Identifiers, quantities, counters | id BIGINT, quantity INT |
| Boolean | BOOLEAN (a synonym of TINYINT(1)) | Yes/no flags | is_active BOOLEAN |
| Fractional numbers | DECIMAL (exact), FLOAT, DOUBLE (approximate) | Money — DECIMAL; measurements and calculations — DOUBLE | price DECIMAL(10,2) |
| Strings | CHAR, VARCHAR, TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT | Names, logins, emails, descriptions | login VARCHAR(50) |
| Binary | BINARY, VARBINARY, TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB | Raw bytes: hashes, small files | uuid BINARY(16) |
| Date and time | DATE, DATETIME, TIMESTAMP, TIME, YEAR | Birth dates, record creation time | created_at DATETIME |
| Special | ENUM, SET, JSON, BIT | A fixed list of values, JSON documents, bit fields | status ENUM('NEW','PAID') |
The type follows the column name in CREATE TABLE; the statement itself is covered in a separate lesson of this module about the CREATE statement. All examples below were checked on MySQL 8 with the strict SQL mode STRICT_TRANS_TABLES, which is on by default. If you do not have a server yet, see How to Run MySQL.
Integer Types: TINYINT, SMALLINT, INT, BIGINT
MySQL has five integer types that differ only in size: TINYINT takes 1 byte, SMALLINT 2, MEDIUMINT 3, INT 4 and BIGINT 8 bytes. More bytes mean a wider range. With the UNSIGNED attribute negative values are not allowed and the upper bound roughly doubles.
| Type | Bytes | Range (SIGNED, default) | UNSIGNED range | Java type |
|---|---|---|---|---|
TINYINT | 1 | -128 to 127 | 0 to 255 | byte or int |
SMALLINT | 2 | -32,768 to 32,767 | 0 to 65,535 | short |
MEDIUMINT | 3 | -8,388,608 to 8,388,607 | 0 to 16,777,215 | int |
INT (INTEGER) | 4 | -2,147,483,648 to 2,147,483,647 | 0 to 4,294,967,295 | int (UNSIGNED — long) |
BIGINT | 8 | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | 0 to 18,446,744,073,709,551,615 | long (UNSIGNED — BigInteger) |
The SIGNED ranges match the Java primitives: TINYINT = byte, SMALLINT = short, INT = int, BIGINT = long. Java has no counterpart of MEDIUMINT, so it is read into an int. There is no integer type called LONG in MySQL: a Java long field maps to BIGINT. INT is enough for most tables; BIGINT is the usual choice for the ids of tables that may grow beyond two billion rows (orders, events, logs).
In strict mode a value outside the range is rejected:
CREATE TABLE people (age TINYINT);
INSERT INTO people (age) VALUES (300); ERROR 1264 (22003): Out of range value for column 'age' at row 1 Without strict mode (sql_mode without STRICT_TRANS_TABLES) MySQL stores the nearest bound of the range — 127 — and only raises a warning that you can see with SHOW WARNINGS.
MySQL UNSIGNED: What It Means
UNSIGNED is an attribute of an integer column that forbids negative values and shifts the whole range into positive numbers: TINYINT UNSIGNED holds 0 to 255 instead of -128 to 127. The size in bytes stays the same.
CREATE TABLE stock (quantity INT UNSIGNED);
INSERT INTO stock (quantity) VALUES (-1); ERROR 1264 (22003): Out of range value for column 'quantity' at row 1 Java has no unsigned integer types, so INT UNSIGNED is read into a long and BIGINT UNSIGNED into a BigInteger: the maximum of 4,294,967,295 does not fit into an int. A foreign key and the column it references must have the same type, UNSIGNED included — see Foreign Key (FOREIGN KEY). UNSIGNED on DECIMAL, FLOAT and DOUBLE is deprecated since MySQL 8.0.17; use a CHECK (price >= 0) constraint instead.
What the Number in INT(11) Means
The number in parentheses after an integer type is neither the size nor a range limit. It is the deprecated display width, which only affected output with ZEROFILL. An INT(5) column stores the same values up to 2,147,483,647 as INT(11). Display width and ZEROFILL are deprecated since MySQL 8.0.17, and since 8.0.19 SHOW CREATE TABLE prints just int. The one exception is TINYINT(1): MySQL keeps it as the marker of a boolean column (see the next section).
Boolean in MySQL: BOOLEAN and TINYINT(1)
MySQL has no separate boolean type: BOOLEAN and BOOL are synonyms of TINYINT(1). The constant TRUE equals 1 and FALSE equals 0, and in conditions any non-zero value counts as true. A BOOLEAN column can therefore store any number from -128 to 127.
CREATE TABLE flags (is_active BOOLEAN);
SHOW CREATE TABLE flags; CREATE TABLE `flags` (
`is_active` tinyint(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci What Will This Query Print?
Try to predict the result: the boolean column receives TRUE, FALSE and the number 5.
INSERT INTO flags (is_active) VALUES (TRUE), (FALSE), (5);
SELECT is_active,
is_active = TRUE AS equals_true,
IF(is_active, 'yes', 'no') AS as_condition
FROM flags; +-----------+-------------+--------------+
| is_active | equals_true | as_condition |
+-----------+-------------+--------------+
| 1 | 1 | yes |
| 0 | 0 | no |
| 5 | 0 | yes |
+-----------+-------------+--------------+ In a condition 5 counts as true, but 5 = TRUE means 5 = 1, which is false. That is why flags are checked with WHERE is_active or WHERE is_active <> 0, not with WHERE is_active = TRUE. To keep anything other than 0 and 1 out of the column, add CHECK (is_active IN (0, 1)) (MySQL enforces CHECK constraints since 8.0.16).
MySQL Connector/J returns TINYINT(1) to Java as a Boolean by default (the tinyInt1isBit=true property), so a boolean field is read with rs.getBoolean().
Fractional Numbers: DECIMAL, FLOAT, DOUBLE
For fractional numbers MySQL offers the exact type DECIMAL and the approximate types FLOAT and DOUBLE. DECIMAL(M,D) keeps exactly D digits after the decimal point with no rounding errors, which makes it the type for money. FLOAT and DOUBLE store a binary approximation of the number, just like float and double in Java.
| Type | Size | Precision | Java type | When to use |
|---|---|---|---|---|
DECIMAL(M,D) (NUMERIC) | Depends on M: 4 bytes per 9 digits | Exact: M is the total number of digits (up to 65), D the digits after the point (up to 30) | BigDecimal | Prices, totals, balances, interest rates |
FLOAT | 4 bytes | Approximate: 24-bit mantissa, about 7 significant digits | float | Rarely: sensor readings where size matters |
DOUBLE (REAL) | 8 bytes | Approximate: 53-bit mantissa, 15–17 significant digits | double | Coordinates, scientific and statistical calculations |
DECIMAL(10,2) stores numbers from -99,999,999.99 to 99,999,999.99: 10 digits in total, 2 of them after the point. Extra decimal places are rounded (10.555 becomes 10.56), while an integer part that is too large triggers ERROR 1264. DECIMAL without parameters means DECIMAL(10,0), i.e. whole numbers only. The FLOAT(M,D) syntax is deprecated since MySQL 8.0.17.
One query shows the difference between an exact and an approximate type. MySQL treats the literal 0.1 as an exact DECIMAL value and 0.1e0 as a DOUBLE:
SELECT 0.1 + 0.2 = 0.3 AS decimal_equal,
0.1e0 + 0.2e0 = 0.3e0 AS double_equal; +---------------+--------------+
| decimal_equal | double_equal |
+---------------+--------------+
| 1 | 0 |
+---------------+--------------+ The sum of two DOUBLE values is 0.30000000000000004, so the comparison is false — exactly like 0.1 + 0.2 == 0.3 in Java. Store prices in DOUBLE, and these fractions of a cent pile up in order totals and reports.
String Types: CHAR, VARCHAR, TEXT
MySQL stores strings in CHAR(M) (fixed length, up to 255 characters), VARCHAR(M) (variable length, set in characters) and the TEXT family for long text. For CHAR and VARCHAR the number M is the maximum number of characters, while the limits of the TEXT types are given in bytes.
| Type | Maximum size | How it is stored | When to use |
|---|---|---|---|
CHAR(M) | 0–255 characters | Always M characters: shorter values are padded with spaces on the right, the spaces are removed on read | Values of the same length: country code 'US', a bcrypt password hash |
VARCHAR(M) | Up to 65,535 bytes for the whole table row; in utf8mb4 no more than 16,383 characters | Length prefix (1–2 bytes) + the characters | Logins, names, emails, product titles |
TINYTEXT | 255 bytes | Length (1 byte) + data | Hardly ever needed: VARCHAR(255) is more convenient |
TEXT | 65,535 bytes (about 64 KB) | Length (2 bytes) + data; long values are stored off the table row | Comments, descriptions, messages |
MEDIUMTEXT | 16,777,215 bytes (about 16 MB) | Length (3 bytes) + data | Articles, HTML pages |
LONGTEXT | 4,294,967,295 bytes (about 4 GB) | Length (4 bytes) + data | Very large documents; in practice the limit is max_allowed_packet |
The default character set in MySQL 8 is utf8mb4, where one character takes 1 to 4 bytes: ASCII letters 1 byte, accented Latin letters such as é 2 bytes, Chinese characters 3 bytes, emoji 4 bytes. So VARCHAR(10) fits 10 characters of any kind, but a TEXT column fits 65,535 ASCII letters and only about 21,845 Chinese characters. The functions LENGTH (bytes) and CHAR_LENGTH (characters) show the difference; other string functions are covered in a separate lesson of this module about SQL functions:
SELECT LENGTH('Java') AS latin_bytes, LENGTH('café') AS accented_bytes, CHAR_LENGTH('café') AS accented_chars; +-------------+----------------+----------------+
| latin_bytes | accented_bytes | accented_chars |
+-------------+----------------+----------------+
| 4 | 5 | 4 |
+-------------+----------------+----------------+ In strict mode a string longer than the declared M is not truncated but rejected:
CREATE TABLE accounts (login VARCHAR(5));
INSERT INTO accounts (login) VALUES ('administrator'); ERROR 1406 (22001): Data too long for column 'login' at row 1 VARCHAR vs TEXT in MySQL
If a value has a sensible length limit (login, email, title), choose VARCHAR; if the text can be of any size (a review, an article), choose TEXT. The differences matter for indexes and default values:
| Property | VARCHAR(M) | TEXT |
|---|---|---|
| Length limit | You set it: M characters | Fixed: 65,535 bytes |
| Length check on insert | More than M characters — ERROR 1406 | Only against the size of the type |
Index and UNIQUE | On the whole value (InnoDB key up to 3,072 bytes) | Only on a prefix: INDEX (about(100)) |
DEFAULT 'text' | Allowed | Not allowed; since MySQL 8.0.13 only an expression in parentheses: DEFAULT ('') |
Where VARCHAR(255) comes from
Before MySQL 5.0.3 a VARCHAR held at most 255 characters, and a length of up to 255 bytes fits into a one-byte prefix. Hence the habit of writing VARCHAR(255) everywhere. In utf8mb4, 255 characters can take up to 1,020 bytes, so the length prefix is 2 bytes anyway and the number 255 saves nothing. Choose the length from the data: 50 for a login, 254 for an email (the RFC 5321 limit).
Binary Types: BINARY, VARBINARY, BLOB
Binary types store a sequence of bytes with no character set and compare it byte by byte. They are BINARY(M) and VARBINARY(M) — the binary counterparts of CHAR and VARCHAR — and the BLOB family, the counterpart of TEXT. All sizes are in bytes; Java reads these columns as byte[].
| Type | Maximum size | Typical use |
|---|---|---|
BINARY(M) | 0–255 bytes, fixed length (padded with 0x00 bytes) | A compact UUID — BINARY(16), a SHA-256 hash — BINARY(32) |
VARBINARY(M) | Up to 65,535 bytes per table row | Short binary values of varying length |
TINYBLOB | 255 bytes | Almost never used |
BLOB | 65,535 bytes (about 64 KB) | Thumbnails, small files |
MEDIUMBLOB | 16,777,215 bytes (about 16 MB) | Documents, images |
LONGBLOB | 4,294,967,295 bytes (about 4 GB) | Large files; the transfer limit is max_allowed_packet (64 MB by default) |
You can keep images and PDFs in the database, but such tables grow fast and backups get heavy. The usual approach is to put the file into file or object storage (for example, Amazon S3) and keep its path in a VARCHAR column.
Date and Time: DATE, DATETIME, TIMESTAMP
MySQL has five date and time types: DATE stores a date only, DATETIME and TIMESTAMP store a date with a time, TIME stores a time of day or an interval, and YEAR stores a year. Values are displayed as YYYY-MM-DD HH:MM:SS. The key differences between DATETIME and TIMESTAMP are the range and the time zone handling.
| Type | Bytes | Format | Range | Java type |
|---|---|---|---|---|
DATE | 3 | YYYY-MM-DD | 1000-01-01 to 9999-12-31 | LocalDate |
DATETIME | 5 (+0–3 for fractional seconds) | YYYY-MM-DD HH:MM:SS | 1000-01-01 00:00:00 to 9999-12-31 23:59:59 | LocalDateTime |
TIMESTAMP | 4 (+0–3 for fractional seconds) | YYYY-MM-DD HH:MM:SS | 1970-01-01 00:00:01 to 2038-01-19 03:14:07 UTC | Instant or LocalDateTime |
TIME | 3 (+0–3) | HH:MM:SS | -838:59:59 to 838:59:59 | LocalTime |
YEAR | 1 | YYYY | 1901 to 2155, and 0000 | int or Year |
Fractional seconds are set in parentheses: DATETIME(3) stores milliseconds, DATETIME(6) microseconds. The two-digit YEAR(2) was removed in MySQL 8.0. On insert MySQL also accepts other notations, such as '2026-11-16 12:00:00', '20261116120000' or the number 20261116, but it always displays dates in the standard format.
DATETIME vs TIMESTAMP
DATETIME stores the date and time exactly as written. TIMESTAMP converts the value from the session time zone (time_zone) to UTC on write and back on read. The same query shows the difference:
CREATE TABLE tz_demo (dt DATETIME, ts TIMESTAMP);
SET time_zone = '+00:00';
INSERT INTO tz_demo VALUES ('2026-11-16 12:00:00', '2026-11-16 12:00:00');
SET time_zone = '-05:00';
SELECT dt, ts FROM tz_demo; +---------------------+---------------------+
| dt | ts |
+---------------------+---------------------+
| 2026-11-16 12:00:00 | 2026-11-16 07:00:00 |
+---------------------+---------------------+ TIMESTAMP suits the moment of an event (“when the order was placed”) when users and servers live in different time zones. But it ends on January 19, 2038, and it does not accept dates before 1970. For birth dates, contract terms and anything beyond 2038, use DATE or DATETIME:
CREATE TABLE persons (birth TIMESTAMP);
INSERT INTO persons (birth) VALUES ('1965-05-10'); ERROR 1292 (22007): Incorrect datetime value: '1965-05-10' for column 'birth' at row 1 ENUM, SET, JSON and BIT
The special MySQL types cover cases where plain numbers and strings are awkward: ENUM holds one value from a predefined list, SET holds several values from a list, JSON holds a JSON document with syntax validation, and BIT(M) holds a set of bits.
| Type | What it stores | Example | Java type |
|---|---|---|---|
ENUM | One value from a list (up to 65,535 options), stored as the option number in 1–2 bytes | status ENUM('NEW','PAID','SHIPPED') | String or a Java enum |
SET | Any combination of values from a list (up to 64 options) | days SET('MON','TUE','WED') | A String such as "MON,WED" |
JSON | A JSON document in a binary format; invalid JSON is rejected | settings JSON | String (parsed with, for example, Jackson) |
BIT(M) | 1 to 64 bits | flags BIT(8) | BIT(1) — Boolean, otherwise byte[] |
An ENUM list can be changed only with ALTER TABLE, so for statuses that keep growing many teams prefer a VARCHAR validated in code or a separate lookup table. MySQL also has spatial types (POINT, POLYGON and others) for coordinates and geometry — Java projects rarely need them.
Which Data Type to Choose for Common Columns
Six types cover most columns of a Java application: BIGINT for ids, DECIMAL for money, BOOLEAN for flags, VARCHAR for short strings, TEXT for long text and DATE/DATETIME for dates. Below are ready-made choices for typical columns.
| Column | MySQL type | Why |
|---|---|---|
| Identifier (id) | BIGINT AUTO_INCREMENT or INT AUTO_INCREMENT | BIGINT will not overflow; INT is enough for lookup tables (UUID vs AUTO_INCREMENT — see the keys lesson FAQ) |
| Price, total, balance | DECIMAL(12,2) | Exact cents; BigDecimal in Java |
| Flag (active, deleted) | BOOLEAN NOT NULL DEFAULT FALSE | 1 byte; boolean in Java |
| Age, quantity in an order | TINYINT UNSIGNED, SMALLINT UNSIGNED or INT | The smallest type that surely fits the values |
| Login | VARCHAR(50) + UNIQUE | A short string with a clear length limit |
VARCHAR(254) | The address length limit of RFC 5321 | |
| Password | CHAR(60) for a bcrypt hash | Never store the password itself — only a fixed-length hash |
| Order status | ENUM(...) or VARCHAR(20) | A fixed set of values |
| Description, review | TEXT | The length is unknown in advance |
| Birth date | DATE | No time needed; TIMESTAMP rejects dates before 1970 |
| Record creation time | DATETIME or TIMESTAMP with DEFAULT CURRENT_TIMESTAMP | The moment of an event; how to choose — DATETIME vs TIMESTAMP |
Here is a customers table of an online shop that uses these types:
CREATE TABLE customers (
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
login VARCHAR(50) NOT NULL UNIQUE,
email VARCHAR(254) NOT NULL,
password_hash CHAR(60) NOT NULL,
balance DECIMAL(12,2) NOT NULL DEFAULT 0.00,
age TINYINT UNSIGNED,
is_active BOOLEAN NOT NULL DEFAULT TRUE,
status ENUM('NEW', 'ACTIVE', 'BLOCKED') NOT NULL DEFAULT 'NEW',
birth_date DATE,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
about TEXT
);
INSERT INTO customers (login, email, password_hash, balance, age, birth_date)
VALUES ('alice', '[email protected]', '$2a$10$shortened-hash', 1500.50, 34, '1992-03-15'); If a type turns out to be a poor choice, it is changed with ALTER TABLE ... MODIFY, which is covered in a separate lesson of this module about changing tables.
MySQL to Java Type Mapping
When you read data through JDBC, every MySQL type maps to a Java type: INT to int, BIGINT to long, DECIMAL to BigDecimal, VARCHAR and TEXT to String, DATE to LocalDate, DATETIME to LocalDateTime. The table lists the recommended field type, the ResultSet method and what the generic getObject(column) returns in Connector/J 8 and later.
| MySQL type | Java field type | How to read from ResultSet | What getObject(column) returns |
|---|---|---|---|
BOOLEAN / TINYINT(1) | boolean | getBoolean() | Boolean |
TINYINT | byte or int | getByte(), getInt() | Integer |
SMALLINT | short | getShort() | Integer |
MEDIUMINT, INT | int | getInt() | Integer |
INT UNSIGNED | long | getLong() | Long |
BIGINT | long | getLong() | Long |
BIGINT UNSIGNED | BigInteger | getObject(col, BigInteger.class) | BigInteger |
DECIMAL | BigDecimal | getBigDecimal() | BigDecimal |
FLOAT / DOUBLE | float / double | getFloat() / getDouble() | Float / Double |
CHAR, VARCHAR, TEXT, ENUM, JSON | String | getString() | String |
BINARY, VARBINARY, BLOB | byte[] | getBytes() | byte[] |
DATE | LocalDate | getObject(col, LocalDate.class) | java.sql.Date |
DATETIME | LocalDateTime | getObject(col, LocalDateTime.class) | LocalDateTime |
TIMESTAMP | Instant or LocalDateTime | getTimestamp(col).toInstant() | java.sql.Timestamp |
TIME | LocalTime | getObject(col, LocalTime.class) | java.sql.Time |
Reading a row of the customers table from the previous section (connecting to the database is covered in the JDBC module):
String sql = "SELECT id, balance, age, is_active, birth_date FROM customers WHERE login = ?";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setString(1, "alice");
try (ResultSet rs = ps.executeQuery()) {
if (rs.next()) {
long id = rs.getLong("id"); // BIGINT
BigDecimal balance = rs.getBigDecimal("balance"); // DECIMAL(12,2)
Integer age = rs.getObject("age", Integer.class); // TINYINT UNSIGNED, may be NULL
boolean active = rs.getBoolean("is_active"); // BOOLEAN
LocalDate birthDate = rs.getObject("birth_date", LocalDate.class); // DATE
System.out.println(id + " " + balance + " " + age + " " + active + " " + birthDate);
}
}
}
// Output: 1 1500.50 34 true 1992-03-15 NULL quietly turns into 0
The methods getInt(), getLong() and getBoolean() return primitives, so for a NULL in the database they give 0 or false — and a customer with no age on file becomes a customer aged zero. For nullable columns use getObject(col, Integer.class) or call rs.wasNull() right after reading.
Common Mistakes When Choosing a Type
Most data type problems surface not when the table is created but months later: cents drift in reports, the id hits its limit, dates sort in the wrong order. Below are the usual missteps, what MySQL does in each case and how to fix it.
| Mistake | What happens | How to fix it |
|---|---|---|
Prices in FLOAT or DOUBLE | Totals drift by fractions of a cent: 0.1e0 + 0.2e0 = 0.3e0 returns 0 | DECIMAL(12,2) and BigDecimal in Java |
Dates in VARCHAR, such as '11/16/2026' | ORDER BY compares strings: '01/05/2027' comes before '11/16/2026'; BETWEEN on dates does not work | DATE or DATETIME; format dates in Java |
Numbers in VARCHAR (VARCHAR instead of INT) | Strings sort character by character: '10' comes before '9'; 'abc' is accepted as a quantity | INT or DECIMAL for anything you count or compare; VARCHAR only for codes such as phone numbers |
Birth date in TIMESTAMP | ERROR 1292: Incorrect datetime value for dates before 1970 | DATE |
INT for the id of a large table | After 2,147,483,647 new inserts fail | BIGINT from the start: switching a live table later means rebuilding it |
VARCHAR that is too short | ERROR 1406: Data too long for column | Length based on real data; if needed, ALTER TABLE ... MODIFY |
WHERE is_active = TRUE | Rows with 2, 5 and so on are left out | WHERE is_active or CHECK (is_active IN (0, 1)) |
rs.getInt() on a nullable column | Java gets 0 instead of a missing value | getObject(col, Integer.class) or rs.wasNull() |
Frequently Asked Questions
Which data type should I use for a phone number?
VARCHAR(20), not a number. You never do arithmetic on a phone number, it can start with + or a zero, and an 11-digit number such as 14155552671 does not even fit into INT (maximum 2,147,483,647). In the international E.164 format a number has up to 15 digits plus the + sign.
How should I store money: DECIMAL or BIGINT in cents?
Both are exact. DECIMAL(12,2) is easier to read: the database shows 1500.50, Java gets a BigDecimal, and SUM and ROUND work without errors. BIGINT in minor units (cents) is popular in payment systems, but it needs conversion everywhere in the code and care with currencies that have three decimal places, such as the Kuwaiti dinar. Why not DOUBLE — see Fractional Numbers.
Is there a LONG type in MySQL?
Not as an integer. For a Java long use BIGINT — it has exactly the same range. MySQL does accept the keyword LONG (and LONG VARCHAR) for compatibility, but it creates a MEDIUMTEXT column, so CREATE TABLE t (n LONG) silently gives you a text column instead of a number.
What is the difference between utf8 and utf8mb4, and why are emoji not saved?
In MySQL utf8 is an alias of the deprecated utf8mb3 character set, which uses at most 3 bytes per character. Emoji and some rare CJK characters need 4 bytes, so inserting 😀 into such a column fails with ERROR 1366: Incorrect string value: '\xF0\x9F\x98\x80'. Real UTF-8 is utf8mb4; MySQL 8 uses it by default for new databases and tables.
Which MySQL types does Hibernate generate for entity fields?
Hibernate 6 with MySQLDialect uses these defaults: Long — bigint, Integer — integer, String — varchar(255), BigDecimal — decimal(38,2), boolean — bit, LocalDate — date, LocalDateTime — datetime(6). Set string lengths and number precision explicitly with @Column(length = 50) and @Column(precision = 12, scale = 2), and in real projects describe the schema with Flyway or Liquibase migrations.
How do MySQL data types differ from PostgreSQL?
PostgreSQL has no TINYINT, MEDIUMINT or UNSIGNED — only smallint, integer and bigint. Its boolean is a real logical type, not a number. text has no 64 KB limit and is as fast as varchar. The counterpart of DATETIME is timestamp, of MySQL’s TIMESTAMP — timestamptz; instead of BLOB there is bytea, and instead of JSON people usually choose jsonb.
Comments