MySQL in XAMPP/MAMP Environment
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
Starting MySQL in XAMPP
Starting MySQL in XAMPP (Windows)
- Open XAMPP Control Panel (Run as Administrator)
- Find the MySQL row in the services list
- Click the "Start" button next to MySQL
- Wait for the status to show "Running" (green indicator)
- 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)
- Open MAMP application
- Click "Start Servers" (both Apache and MySQL start together)
- Wait for green indicators next to both servers
- The WebStart page will open automatically
- 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
| 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!
Troubleshooting Common Issues
🔴 MySQL Won't Start
Problem: Port 3306 already in use
🟡 Access Denied Error
Problem: Can't connect to MySQL
🟢 Best Practices
Keep Your Development Environment Clean
Practice Exercise
Hands-On Practice
- Start MySQL in your XAMPP/MAMP environment
- Connect to MySQL via command line
- Create a test database called
test_environment - Check your MySQL version:
SELECT VERSION(); - List all databases:
SHOW DATABASES; - Find your MySQL configuration file and note the location
- Access phpMyAdmin through your browser