MySQL XAMPP Localhost Setup
In this topic, you will learn how to install and start MySQL using XAMPP. XAMPP is an easy-to-install package that bundles Apache (web server), MySQL/MariaDB (database), PHP, and other tools. After completing this page, you will be able to:
http://localhost or http://localhost/xampp).http://localhost or http://localhost/xampp in your browser.http://localhost/phpmyadmin.
// Steps to start MySQL from XAMPP Control Panel (summary)
1. Open XAMPP Control Panel.
2. Click the "Start" button next to Apache.
3. Click the "Start" button next to MySQL.
4. Wait until both modules are highlighted in green.
5. Open your browser and visit: http://localhost/phpmyadmin
Once MySQL is running, you can access and manage your databases using phpMyAdmin:
http://localhost/phpmyadmin.
// Example SQL query to create a database in phpMyAdmin
CREATE DATABASE xampp_demo_db;
USE xampp_demo_db;
CREATE TABLE students (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100),
course VARCHAR(100)
);
XAMPP also allows you to use the MySQL command line client. On Windows, you can use the "Shell" button in XAMPP Control Panel to open a terminal window.
// Log in to MySQL server from XAMPP shell using root user
mysql -u root
// After logging in, you can run SQL commands
SHOW DATABASES;
CREATE DATABASE cli_demo;
USE cli_demo;
SHOW TABLES;
To verify that PHP can connect to MySQL inside XAMPP, create a simple PHP file in the htdocs folder (for example: C:\xampp\htdocs\mysql_test.php on Windows).
// mysql_test.php - Simple script to test MySQL connection via XAMPP
<?php
$host = "localhost"; // MySQL server is running on localhost
$user = "root"; // Default XAMPP user
$pass = ""; // Default XAMPP password is empty
$db = "test"; // Existing database name (e.g. 'test')
$conn = new mysqli($host, $user, $pass, $db);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "✅ Connected successfully to MySQL using XAMPP!";
$conn->close();
?>
If everything is configured correctly, opening http://localhost/mysql_test.php in your browser should display:
✅ Connected successfully to MySQL using XAMPP!
If you see an error message instead, carefully read the error; it usually tells you whether the problem is with the database name, username, password, or connection settings.
C:\xampp\htdocs\mysite).http://localhost/phpmyadmin and create a new database named practice_db.practice_db, create a table users with fields id, name, and email.db_connect.php inside htdocs that connects to practice_db and prints a success message.users table and verify it inside phpMyAdmin.