ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

MySQL Relational Database Tutorial• 5 min read

MySQL Introduction & Data Types

MySQL is an open-source Relational Database Management System (RDBMS) developed by Oracle, renowned for extreme query speed, reliability, and widespread deployment.

Relational Architecture & Schema Design

A relational database organizes data into rows and columns within strictly defined tables. Each table has a defined schema that enforces data integrity, primary keys, and relationships via foreign keys.

Data is structured according to normalized entity schemas to prevent redundant data duplication.

Creating a Normalized MySQL Table
CREATE DATABASE IF NOT EXISTS codexia_store;
USE codexia_store;

CREATE TABLE Users (
    UserID INT AUTO_INCREMENT PRIMARY KEY,
    Username VARCHAR(50) NOT NULL UNIQUE,
    Email VARCHAR(100) NOT NULL UNIQUE,
    AccountBalance DECIMAL(10, 2) DEFAULT 0.00,
    CreatedAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB;

Core MySQL Data Types

Choosing optimal data types reduces disk consumption and dramatically speeds up in-memory buffer indexing:

CategoryData TypeStorage SizeIdeal Use Case
IntegerINT / BIGINT4 / 8 BytesPrimary keys, quantities, counters
DecimalsDECIMAL(M, D)VariableExact currency & financial amounts (no floating-point drift)
StringsVARCHAR(N)Length + 1 ByteUsernames, emails, addresses up to N chars
TimestampTIMESTAMP4 BytesAutomatic record creation/update timestamps
ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

Which MySQL data type should always be used for storing financial currency values to avoid floating-point approximation errors?