Introduction to MySQL Databases
Learn what MySQL is, why it’s widely used, and how to create your first database and table with practical examples.
What is MySQL?
MySQL is a popular open-source relational database management system (RDBMS). It allows you to store, organize, and retrieve data efficiently. MySQL is widely used in web development, backend systems, and applications where structured data is required.
Key Features:
- Open-source and free
- Fast and reliable
- Supports relational data with tables, rows, and columns
- Works with many programming languages like PHP, Python, and JavaScript
Setting Up MySQL
Before you start, make sure MySQL is installed on your system. You can check by running:
mysql --version
If installed correctly, you’ll see the MySQL version
Creating Your First Database
Let’s create a simple database for a user management system:
n.
-- Create a new database CREATE DATABASE my_first_db; -- Switch to the new database USE my_first_db;
Creating Your First Table
We’ll create a users table to store basic user information:
CREATE TABLE users ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50) NOT NULL, email VARCHAR(50) UNIQUE NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
Explanation:
id– unique identifier for each username– user’s nameemail– user’s email, must be uniquecreated_at– timestamp when the record is added
Inserting Data
Add your first record to the table:
INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com');
Reading Data
Retrieve all records from the table:
SELECT * FROM users;
Output:
id name. email. created_at
1 Alice alice@example.com 2026-02-19 12:00:00
Tips for Beginners
- Use
DESCRIBE table_name;to see the structure of any table. - Remember that SQL statements end with a semicolon (
;). - Practice creating tables and inserting data—it’s the best way to learn.