Skip to main content

Course Progress

Loading...

MySQL in XAMPP/MAMP Environment

Duration: 60 minutes
Module 3: Session 1

Learning Objectives

  • Understand how MySQL is integrated into XAMPP and MAMP
  • Learn to start and stop MySQL services
  • Configure MySQL settings in your development environment
  • Access MySQL through command line and GUI tools
  • Troubleshoot common MySQL issues in local development

Understanding the Stack

XAMPP and MAMP are development stacks that bundle Apache, MySQL, and PHP together. Let's explore how MySQL fits into these environments.

graph TB subgraph "XAMPP Stack" X1[Apache Web Server] X2[MySQL Database] X3[PHP] X4[Perl] end subgraph "MAMP Stack" M1[Apache Web Server] M2[MySQL Database] M3[PHP] M4[Python/Perl] end X2 --> DB[(Your Databases)] M2 --> DB style X2 fill:#00758f,color:white style M2 fill:#00758f,color:white style DB fill:#e6f3ff
💡
Stack Names Explained
XAMPP:X (Cross-platform), A (Apache), M (MySQL), P (PHP), P (Perl)
MAMP:M (Mac/My), A (Apache), M (MySQL), P (PHP)

Starting MySQL in XAMPP

Starting MySQL in XAMPP (Windows)

  1. Open XAMPP Control Panel (Run as Administrator)
  2. Find the MySQL row in the services list
  3. Click the "Start" button next to MySQL
  4. Wait for the status to show "Running" (green indicator)
  5. Note the port number (default: 3306)
# Alternative: Start from command line
C:\xampp\mysql\bin\mysqld.exe

# To stop MySQL
C:\xampp\mysql\bin\mysqladmin.exe -u root shutdown

Starting MySQL in MAMP

Starting MySQL in MAMP (macOS)

  1. Open MAMP application
  2. Click "Start Servers" (both Apache and MySQL start together)
  3. Wait for green indicators next to both servers
  4. The WebStart page will open automatically
  5. MySQL runs on port 8889 by default (not 3306!)
# Alternative: Start from Terminal
/Applications/MAMP/Library/bin/mysql.server start

# To stop MySQL
/Applications/MAMP/Library/bin/mysql.server stop

# Connect to MySQL in MAMP
/Applications/MAMP/Library/bin/mysql -uroot -proot

MySQL Configuration Files

⚠️
Important Locations
Know where your MySQL configuration and data files are located!
Component XAMPP (Windows) MAMP (macOS)
MySQL Config C:\xampp\mysql\bin\my.ini /Applications/MAMP/conf/my.cnf
Data Directory C:\xampp\mysql\data\ /Applications/MAMP/db/mysql57/
Error Log C:\xampp\mysql\data\mysql_error.log /Applications/MAMP/logs/mysql_error.log
Default Port 3306 8889
Default User root (no password) root / root

Accessing MySQL Command Line

graph LR A[Terminal/CMD] --> B[MySQL Client] B --> C[MySQL Server] C --> D[(Databases)] B -->|Commands| E[CREATE DATABASE] B -->|Commands| F[SHOW TABLES] B -->|Commands| G[SELECT * FROM] style B fill:#00758f,color:white style C fill:#ff6423,color:white

XAMPP MySQL Access

# Windows: Open Command Prompt
cd C:\xampp\mysql\bin

# Connect to MySQL (no password by default)
mysql -u root

# Or with password if you set one
mysql -u root -p

MAMP MySQL Access

# macOS: Open Terminal
cd /Applications/MAMP/Library/bin

# Connect to MySQL (password is 'root')
./mysql -u root -p
# Enter password: root

# Or specify the socket
./mysql -u root -p --socket=/Applications/MAMP/tmp/mysql/mysql.sock

First MySQL Commands

-- Once connected, try these commands:

-- Show all databases
SHOW DATABASES;

-- Create a new database
CREATE DATABASE my_first_db;

-- Use the database
USE my_first_db;

-- Create a simple table
CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100),
    email VARCHAR(100)
);

-- Insert some data
INSERT INTO users (name, email) 
VALUES ('John Doe', 'john@example.com');

-- View the data
SELECT * FROM users;

-- Exit MySQL
EXIT;

MySQL Port Configuration

⚠️
MAMP Users: Important!
MAMP uses port 8889 for MySQL by default. When configuring WordPress or PHP applications, use:
// For MAMP:
define('DB_HOST', 'localhost:8889');

// For XAMPP:
define('DB_HOST', 'localhost');

Troubleshooting Common Issues

🔴 MySQL Won't Start

Problem: Port 3306 already in use
Solution:
  1. Check if another MySQL is running
  2. Stop the other MySQL service
  3. Or change XAMPP MySQL port in config
# Windows: Check what's using port 3306
netstat -ano | findstr :3306

# Mac: Check what's using port 8889
lsof -i :8889

🟡 Access Denied Error

⚠️
Problem: Can't connect to MySQL
Solutions:
  • XAMPP: Try without password first (default)
  • MAMP: Default password is 'root'
  • Reset password if needed

🟢 Best Practices

Keep Your Development Environment Clean
  • Always stop services when not in use
  • Back up your databases regularly
  • Set a root password for security
  • Document your port configurations
  • Keep XAMPP/MAMP updated

Practice Exercise

💻
Hands-On Practice
Complete these tasks:
  1. Start MySQL in your XAMPP/MAMP environment
  2. Connect to MySQL via command line
  3. Create a test database calledtest_environment
  4. Check your MySQL version:SELECT VERSION();
  5. List all databases:SHOW DATABASES;
  6. Find your MySQL configuration file and note the location
  7. Access phpMyAdmin through your browser

Additional Resources