Back to Blog
    Web Development and Databases

    How to Create a Database Using XAMPP: Complete Step-by-Step Guide

    Steve Ronald
    January 4, 2026
    10 min read
     How to Create a Database Using XAMPP: Complete Step-by-Step Guide

    How to Create a Database Using XAMPP: Complete Step-by-Step Guide

    Creating a database is essential for web development. XAMPP makes it incredibly easy to set up a local database server on your computer without complex configurations.

    This guide walks you through every single step of installing XAMPP, creating databases, and managing them using phpMyAdmin. No steps are skipped.


    Table of Contents


    What is XAMPP and Why Use It?

    XAMPP is a free, open-source software package that includes:

    • Apache - Web server
    • MySQL - Database server
    • PHP - Programming language
    • phpMyAdmin - Database management tool

    Why Developers Use XAMPP

    • Free and open-source
    • Easy to install - One-click installation
    • Cross-platform - Works on Windows, Mac, Linux
    • Perfect for local development - Test websites before going live
    • No internet required - Everything runs locally

    Step 1: Download and Install XAMPP

    Download XAMPP

    1. Visit the official website: https://www.apachefriends.org

    2. Click the download button for your operating system:

      • Windows (most common)
      • Mac OS X
      • Linux
    3. Choose the latest version (usually PHP 8.x)

    4. Download will start automatically (file size: ~150-200 MB)

    Install XAMPP on Windows

    1. Locate the downloaded file (usually in Downloads folder)

      • File name: xampp-windows-x64-8.x.x-installer.exe
    2. Right-click the installerRun as Administrator

    3. Windows Security warning may appear:

      • Click "Yes" to allow installation
    4. XAMPP Setup Wizard opens:

      • Click "Next"
    5. Select Components screen:

      • Keep all default selections checked:
        • ✅ Apache
        • ✅ MySQL
        • ✅ PHP
        • ✅ phpMyAdmin
      • Click "Next"
    6. Installation folder screen:

      • Default: C:\xampp
      • Keep this default (recommended)
      • Click "Next"
    7. Language selection:

      • Choose English
      • Click "Next"
    8. Ready to Install screen:

      • Click "Next"
    9. Installation progress:

      • Wait 2-5 minutes
      • Files are being extracted and installed
    10. Installation complete:

      • ✅ Check "Do you want to start the Control Panel now?"
      • Click "Finish"

    Expected Output

    After installation:

    • XAMPP is installed in C:\xampp
    • XAMPP Control Panel opens automatically
    • Desktop shortcut is created (optional)

    Step 2: Start Apache and MySQL Services

    Open XAMPP Control Panel

    If not already open:

    1. Go to C:\xampp
    2. Double-click xampp-control.exe
    3. Or use the desktop shortcut

    Start Required Services

    The XAMPP Control Panel shows all available services:

    1. Locate Apache in the list

      • Click "Start" button next to Apache
      • Wait for status to show green background
      • Port numbers appear: 80, 443
    2. Locate MySQL in the list

      • Click "Start" button next to MySQL
      • Wait for status to show green background
      • Port number appears: 3306

    Expected Output

    When services are running:

    • Apache: Green background, shows "Running" status
    • MySQL: Green background, shows "Running" status
    • Both services show PID (Process ID) numbers

    Troubleshooting Port Conflicts

    If Apache won't start:

    Problem: Port 80 is already in use (often by Skype or IIS)

    Solution:

    1. Click "Config" button next to Apache
    2. Select "Apache (httpd.conf)"
    3. Find line: Listen 80
    4. Change to: Listen 8080
    5. Save and close
    6. Click "Start" again

    If MySQL won't start:

    Problem: Port 3306 is already in use

    Solution:

    1. Click "Config" button next to MySQL
    2. Select "my.ini"
    3. Find line: port=3306
    4. Change to: port=3307
    5. Save and close
    6. Click "Start" again

    Step 3: Access phpMyAdmin

    Open phpMyAdmin

    1. Open your web browser (Chrome, Firefox, Edge, etc.)
    2. Type in the address bar: http://localhost/phpmyadmin
    3. Press Enter

    Expected Output

    You should see:

    • phpMyAdmin dashboard loads
    • Left sidebar shows existing databases
    • Top navigation shows tabs: Databases, SQL, Status, etc.
    • Welcome screen in the main area

    Default Login (if prompted)

    • Username: root
    • Password: (leave blank)
    • Click "Go"

    Step 4: Create Your First Database

    Using phpMyAdmin Interface

    1. Click "Databases" tab at the top

    2. Find "Create database" section

    3. Enter database name in the text field:

      • Example: my_first_database
      • Use lowercase, no spaces
      • Use underscores instead of spaces
    4. Select Collation (optional):

      • Default: utf8mb4_general_ci (recommended)
      • This handles international characters
    5. Click "Create" button

    Expected Output

    After creation:

    • Success message appears: "Database my_first_database has been created"
    • New database appears in left sidebar
    • Database is empty (0 tables)

    Create Multiple Databases

    Repeat the process for different projects:

    my_blog_database
    ecommerce_store
    portfolio_site
    test_database
    

    Step 5: Create Tables in Your Database

    Select Your Database

    1. Click your database name in the left sidebar
    2. Main area shows "No tables found in database"

    Create a Table

    1. Find "Create table" section
    2. Enter table name: Example: users
    3. Enter number of columns: Example: 5
    4. Click "Go"

    Define Table Structure

    A form appears with rows for each column:

    Example: Creating a "users" table

    Column NameTypeLengthDefaultAttributesNullIndexA_I
    idINT11NoneUNSIGNEDPRIMARY
    usernameVARCHAR50None--
    emailVARCHAR100None-UNIQUE
    passwordVARCHAR255None--
    created_atTIMESTAMP-CURRENT_TIMESTAMP--

    Step-by-step for each column:

    Column 1: id

    • Name: id
    • Type: Select INT
    • Length: 11
    • Attributes: Select UNSIGNED
    • Null: Uncheck (not null)
    • Index: Select PRIMARY
    • A_I (Auto Increment): Check ✅

    Column 2: username

    • Name: username
    • Type: Select VARCHAR
    • Length: 50
    • Null: Uncheck (not null)

    Column 3: email

    • Name: email
    • Type: Select VARCHAR
    • Length: 100
    • Null: Uncheck (not null)
    • Index: Select UNIQUE

    Column 4: password

    • Name: password
    • Type: Select VARCHAR
    • Length: 255
    • Null: Uncheck (not null)

    Column 5: created_at

    • Name: created_at
    • Type: Select TIMESTAMP
    • Default: Select CURRENT_TIMESTAMP
    • Null: Uncheck (not null)

    Save the Table

    1. Scroll down
    2. Click "Save" button at the bottom

    Expected Output

    • Success message: "Table users has been created"
    • Table appears in left sidebar under your database
    • Table structure is displayed

    Step 6: Insert Data into Tables

    Method 1: Using phpMyAdmin Interface

    1. Click your table name (users) in the sidebar
    2. Click "Insert" tab at the top
    3. Fill in the form:

    Example data:

    • id: (leave blank - auto increment)
    • username: john_doe
    • email: john@example.com
    • password: hashed_password_here
    • created_at: (leave default)
    1. Click "Go" at the bottom

    Insert Multiple Rows

    1. After first insert, form reappears
    2. Enter another user:
      • username: jane_smith
      • email: jane@example.com
      • password: another_hashed_password
    3. Click "Go"

    Method 2: Using SQL Query

    1. Click "SQL" tab at the top
    2. Enter SQL query:
    INSERT INTO users (username, email, password) VALUES
    ('john_doe', 'john@example.com', 'hashed_password_1'),
    ('jane_smith', 'jane@example.com', 'hashed_password_2'),
    ('bob_wilson', 'bob@example.com', 'hashed_password_3');
    
    1. Click "Go"

    View Your Data

    1. Click "Browse" tab
    2. See all inserted data in a table format

    Expected Output

    • Data is inserted successfully
    • Browse tab shows all rows
    • Each row has a unique auto-incremented ID

    Step 7: Connect to Database Using PHP

    Create a PHP Connection File

    1. Open your text editor (VS Code, Notepad++, etc.)
    2. Create new file: db_connect.php
    3. Save in: C:\xampp\htdocs\

    PHP Connection Code

    <?php
    // Database configuration
    $host = 'localhost';
    $username = 'root';
    $password = '';
    $database = 'my_first_database';
    
    // Create connection
    $conn = new mysqli($host, $username, $password, $database);
    
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }
    
    echo "Connected successfully to database!";
    
    // Close connection when done
    // $conn->close();
    ?>
    

    Test the Connection

    1. Save the file
    2. Open browser
    3. Go to: http://localhost/db_connect.php

    Expected Output

    Browser displays: "Connected successfully to database!"

    Fetch Data from Database

    Create fetch_users.php:

    <?php
    // Include connection file
    include 'db_connect.php';
    
    // SQL query
    $sql = "SELECT * FROM users";
    $result = $conn->query($sql);
    
    // Check if data exists
    if ($result->num_rows > 0) {
        echo "<h2>Users List</h2>";
        echo "<table border='1'>";
        echo "<tr><th>ID</th><th>Username</th><th>Email</th><th>Created At</th></tr>";
        
        // Output data
        while($row = $result->fetch_assoc()) {
            echo "<tr>";
            echo "<td>" . $row["id"] . "</td>";
            echo "<td>" . $row["username"] . "</td>";
            echo "<td>" . $row["email"] . "</td>";
            echo "<td>" . $row["created_at"] . "</td>";
            echo "</tr>";
        }
        
        echo "</table>";
    } else {
        echo "No users found";
    }
    
    $conn->close();
    ?>
    

    Test Data Fetching

    1. Save the file in C:\xampp\htdocs\
    2. Open browser
    3. Go to: http://localhost/fetch_users.php

    Expected Output

    Browser displays:

    • "Users List" heading
    • Table with all users from database
    • Columns: ID, Username, Email, Created At

    Common Issues and Solutions

    Issue 1: XAMPP Control Panel Won't Open

    Solution:

    • Right-click xampp-control.exe
    • Select "Run as Administrator"
    • If still fails, restart your computer

    Issue 2: Apache Won't Start (Port 80 Busy)

    Solution:

    • Change Apache port to 8080 (see Step 2)
    • Or stop conflicting programs (Skype, IIS)

    Issue 3: MySQL Won't Start

    Solution:

    • Check if MySQL service is already running in Windows Services
    • Stop the existing MySQL service
    • Or change MySQL port in XAMPP

    Issue 4: "Access Denied" Error in phpMyAdmin

    Solution:

    • Username: root
    • Password: (leave blank)
    • If changed, use your custom password

    Issue 5: PHP File Downloads Instead of Running

    Solution:

    • Make sure Apache is running
    • Save PHP files in C:\xampp\htdocs\
    • Access via http://localhost/filename.php (not file path)

    Issue 6: Database Connection Failed

    Solution:

    • Verify MySQL is running in XAMPP Control Panel
    • Check database name spelling
    • Ensure username is root and password is blank (default)

    Best Practices

    Security Tips

    1. Change root password:

      • Open phpMyAdmin
      • Click "User accounts"
      • Edit root user
      • Set a strong password
    2. Don't use root in production:

      • Create separate users for each database
      • Grant only necessary permissions
    3. Backup regularly:

      • Export databases from phpMyAdmin
      • Save .sql files

    Database Naming Conventions

    • Use lowercase letters
    • Use underscores instead of spaces
    • Be descriptive: blog_posts not bp
    • Avoid special characters

    Table Design Tips

    • Always include an id column (primary key, auto increment)
    • Use appropriate data types (INT for numbers, VARCHAR for text)
    • Add timestamps (created_at, updated_at)
    • Set NOT NULL for required fields

    Next Steps

    Now that you have XAMPP set up:

    1. Practice creating databases for different projects
    2. Learn SQL queries (SELECT, INSERT, UPDATE, DELETE)
    3. Build PHP applications that interact with databases
    4. Explore phpMyAdmin features (import, export, search)
    5. Study database relationships (foreign keys, joins)

    Useful Resources


    You now have a fully functional local database server! Start building database-driven applications with confidence.

    You can also check our official website: Codecraft Academy for more blogs and courses.

    Comments (0)

    Leave a Comment

    No comments yet. Be the first to comment!