Guide to Creating MySQL Tables and Adding Data
Meta Description:
Learn step by step how to create a table, insert data and update records using the $CREATE$ $TABLE$, $INSERT$ and $UPDATE$ commands in MySQL.
💡 What Will You Learn in This Guide?
In this beginner's guide, you'll learn how to create tables and insert data in MySQL.
Also:
- You will learn the concepts of primary key ($PRIMARY$ $KEY$) and auto increment ($AUTO_INCREMENT$).
- You will apply $INSERT$, $UPDATE$ and $SELECT$ queries with practical examples.
🎯 Purpose: To learn to create your own database and manage records.
🧠 Basic Information and Requirements
Before you start, have:
- An installed and configured MySQL server (example: GenixNode server).
- Basic SQL command knowledge.
- MySQL command line or MySQL Workbench access.
To connect to MySQL:
mysql -u kullanıcı_adı -p
This command starts the MySQL session.
1️⃣ Creating and Selecting a Database
Every table is located in a database. First, let's create a database called genixnode_app:
CREATE DATABASE genixnode_uyg;
USE genixnode_uyg;
This command creates and activates a new database.
2️⃣ Creating a Table ($CREATE$ $TABLE$)
A table consists of column names and data types.
CREATE TABLE kullanicilar (
id INT PRIMARY KEY AUTO_INCREMENT,
ad VARCHAR(100),
eposta VARCHAR(255) UNIQUE,
kayit_tarihi DATE
);
| Column | Data Type and Constraint | Description |
|---|---|---|
id | INT PRIMARY KEY AUTO_INCREMENT | Unique for each row, automatically incremented. |
ad | VARCHAR(100) | Username, up to 100 characters. |
eposta | VARCHAR(255) UNIQUE | The email address must be unique. |
kayit_tarihi | DATE | The date the record was created. |
✅ This table is now ready to add data.
3️⃣ Adding Data to Table ($INSERT$ $INTO$)
Adding a Single Record
INSERT INTO kullanicilar (ad, eposta, kayit_tarihi)
VALUES ('Murat Yılmaz', 'murat@ornek.com', '2025-10-01');
Adding Multiple Records
INSERT INTO kullanicilar (ad, eposta, kayit_tarihi)
VALUES
('Gizem Demir', 'gizem@ornek.com', '2025-10-02'),
('Ali Can', 'ali@ornek.com', '2025-10-03');
💡 Multiple insertions in a single query increases performance.
4️⃣ Viewing Data ($SELECT$)
To check that the data has been added correctly:
SELECT * FROM kullanicilar;
| id | name | registration_date | |
|---|---|---|---|
| 1 | Murat Yilmaz | murat@ornek.com | 2025-10-01 |
| 2 | Gizem Demir | gizem@ornek.com | 2025-10-02 |
| 3 | Ali Can | ali@ornek.com | 2025-10-03 |
5️⃣ Registration Update ($UPDATE$)
UPDATE kullanicilar
SET eposta = 'murat.yilmaz@ornek.com'
WHERE id = 1;
🔄 The email of the user with id=1 is updated.
To verify the change:
SELECT * FROM kullanicilar;
🔎 Most Frequently Used SQL Commands
| Command | Description |
|---|---|
CREATE DATABASE | Creates new database |
USE | Activates the database |
CREATE TABLE | Creates new table |
INSERT INTO | Adds new record |
SELECT | Displays data |
UPDATE | Updates records |
REPLACE | Updates if available, adds if not |
DROP TABLE | Deletes table |
⚠️ Common Errors
1️⃣ “Table already exists”
If there is a table with the same name, it gives an error.
CREATE TABLE IF NOT EXISTS kullanicilar (...);
2️⃣ Incorrect data type
Adding a value that does not match the data type will cause an error.
age INT NOT NULL;
INSERT INTO kullanicilar (ad, age) VALUES ('Ali', 'yirmi'); -- ❌ Hatalı
3️⃣ Syntax Errors
Missing parentheses or quotes will cause an error.
INSERT INTO kullanicilar (ad, eposta VALUES ('Ali', 'ali@ornek.com'); -- ❌ Eksik parantez
💬 Frequently Asked Questions (FAQ)
- Is it mandatory to define a PRIMARY KEY?
No, but it is recommended for data integrity.
- What is the difference between CHAR and VARCHAR?
CHAR is fixed length, VARCHAR is stored in variable length.
- What is the difference between INSERT, INSERT IGNORE and REPLACE?
INSERT: If there is a record, it gives an error.
INSERT IGNORE: Ignores the error.
REPLACE: Updates the record if there is one, adds it otherwise.
- What is SQL injection and how to prevent it?
Insert data securely using Prepared Statements.
$stmt = $conn->prepare("INSERT INTO kullanicilar (ad, eposta) VALUES (?, ?)");
$stmt->bind_param("ss", $ad, $eposta);
$stmt->execute();
- How do I copy the table?
CREATE TABLE yedek_kullanicilar SELECT * FROM kullanicilar;
🏁 Result
Now you know how to create a table, insert data and update records in MySQL. These basics form the backbone of your backend development process.
☁️ By hosting your application on GenixNode, you can test MySQL performance in real environments.

