MySQL Installation
System Requirements
Before installing MySQL, ensure your system meets the minimum requirements:
Hardware Requirements
| Component |----------------|--------------|-----------------| | CPU | RAM | Disk Space | Network
Software Requirements
MySQL is available on multiple platforms:
- Windows: Windows 10/11, Windows Server 2016+
- macOS: macOS 10.15+
- Linux: Most distributions (Ubuntu, Debian, CentOS, RHEL, etc.)
- Unix: FreeBSD, Solaris
Windows Installation
Method 1: MySQL Installer (Recommended)
Download MySQL Installer
- Visit https://dev.mysql.com/downloads/installer/
- Download mysql-installer-community-8.0.x.msi
Run the Installer
- Double-click the downloaded .msi file
- If prompted by User Account Control, click "Yes"
Choose Setup Type
- Developer Default: Includes MySQL Server, MySQL Workbench - Full: Includes all MySQL products - Server Only: MySQL Server only - Custom: Select specific componentsCheck Requirements
- Installer will check for missing prerequisites
- Install any required components
Installation
- Review components to install
- Click "Execute" to begin installation
- Wait for download and installation
Configuration
- Configuration type: Standalone
- Port: 3306 (default)
- Authentication method: Strong password encryption
- Set root password
- Create user accounts (optional)
Complete Installation
- Click "Finish" when complete
Method 2: ZIP Archive
Download MySQL ZIP Archive
- Visit https://dev.mysql.com/downloads/mysql/
- Download mysql-8.0.x-winx64.zip
Extract Files
powershell# Extract to desired location Expand-Archive mysql-8.0.x-winx64.zip -DestinationPath C:\mysqlInitialize MySQL
cmdcd C:\mysql mkdir data bin\mysqld --initialize-insecure --basedir=. --datadir=./dataStart MySQL Service
cmdbin\mysqld --install net start mysqlConnect to MySQL
cmdbin\mysql -u root -p
Method 3: Docker
# Pull MySQL image
docker pull mysql:8.0
# Run MySQL container
docker run --name mysql-dev `
-e MYSQL_ROOT_PASSWORD=my-secret-pw `
-p 3306:3306 `
-d mysql:8.0
# Connect to MySQL
docker exec -it mysql-dev mysql -u root -pmacOS Installation
Method 1: Homebrew (Recommended)
Install Homebrew
bash/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Install MySQL
bashbrew install mysql@8.0 # Start MySQL service brew services start mysql@8.0 # Or start manually mysql.server startInitial Setup
bash# Secure installation mysql_secure_installation # Or connect directly mysql -u rootAdd to PATH
bashecho 'export PATH="/usr/local/opt/mysql@8.0/bin:$PATH"' >> ~/.zshrc source ~/.zshrc
Method 2: DMG Package
Download DMG Package
- Visit https://dev.mysql.com/downloads/mysql/
- Download mysql-8.0.x-macos11-x86_64.dmg
Run Installation
- Open the downloaded .dmg file
- Double-click mysql-8.0.x.pkg
- Follow installation wizard
- Set temporary password (shown in installer)
Start MySQL
bash# Using System Preferences # Open MySQL preference pane # Click "Start MySQL Server" # Or using command line sudo mysql.server startChange Root Password
bashsudo mysql -u root -p # Use temporary password from installation ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword123!';
Method 3: Docker
# Pull MySQL image
docker pull mysql:8.0
# Run MySQL container
docker run --name mysql-dev \
-e MYSQL_ROOT_PASSWORD=my-secret-pw \
-p 3306:3306 \
-d mysql:8.0
# Connect to MySQL
docker exec -it mysql-dev mysql -u root -pLinux Installation
Ubuntu / Debian
Step 1: Update Package Index
sudo apt updateStep 2: Install MySQL
# Install MySQL Server
sudo apt install mysql-server
# Install MySQL Client
sudo apt install mysql-client
# Install MySQL development files
sudo apt install libmysqlclient-devStep 3: Secure MySQL Installation
sudo mysql_secure_installationThe secure installation script will guide you through:
Securing the MySQL server deployment.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks password strength and
allows setting only passwords which meet the current
policy requirements.
Would you like to setup VALIDATE PASSWORD component? [Y/N]: Y
Please set the password for root here.
New password: ********
Confirm new password: ********
Remove anonymous users? [Y/N]: Y
Disallow root login remotely? [Y/N]: Y
Remove test database and access to it? [Y/N]: Y
Reload privilege tables now? [Y/N]: YStep 4: Start MySQL Service
# Start MySQL service
sudo systemctl start mysql
# Enable MySQL to start on boot
sudo systemctl enable mysql
# Check service status
sudo systemctl status mysqlStep 5: Connect to MySQL
sudo mysql -u root -pCentOS / RHEL / Rocky Linux
Step 1: Add MySQL Repository
# Download MySQL repository package
sudo dnf localinstall https://dev.mysql.com/get/mysql80-community-release-el8-7.noarch.rpm
# Enable MySQL 8.0 repository
sudo dnf module enable mysql:8.0
# Or for CentOS 7
sudo yum localinstall https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpmStep 2: Install MySQL
# Install MySQL community server
sudo dnf install mysql-community-server
# Install MySQL client
sudo dnf install mysql-community-clientStep 3: Start MySQL Service
# Start MySQL service
sudo systemctl start mysqld
# Enable MySQL to start on boot
sudo systemctl enable mysqld
# Check temporary password
sudo grep 'temporary password' /var/log/mysqld.logStep 4: Secure Installation
# Get temporary password
TEMP_PASSWORD=$(sudo grep 'temporary password' /var/log/mysqld.log | awk '{print $NF}')
# Run secure installation
sudo mysql -u root -p"$TEMP_PASSWORD" -e "
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewStrongPassword123!';
FLUSH PRIVILEGES;
"
# Or run full secure installation
sudo mysql_secure_installationFedora / Fedora
# Install MySQL
sudo dnf install mysql mysql-server
# Start and enable service
sudo systemctl start mysqld
sudo systemctl enable mysqld
# Secure installation
sudo mysql_secure_installationVerification
Check MySQL Version
# Command line
mysql --version
# In MySQL
mysql -u root -p
SELECT VERSION();Test Connection
# Local connection
mysql -u root -p
# Test basic commands
SHOW DATABASES;
CREATE DATABASE test_db;
DROP DATABASE test_db;Check Service Status
# Linux (systemd)
sudo systemctl status mysql
sudo systemctl status mysqld
# macOS
brew services list | grep mysql
# Check if MySQL is running
sudo netstat -tlnp | grep 3306Post-Installation Configuration
Setting Root Password
-- Method 1: ALTER USER
ALTER USER 'root'@'localhost' IDENTIFIED BY 'YourStrongPassword123!';
-- Method 2: SET PASSWORD
SET PASSWORD FOR 'root'@'localhost' = 'YourStrongPassword123!';
-- Method 3: Using mysqladmin
mysqladmin -u root password 'YourStrongPassword123!'Creating a New User
-- Create a user with full privileges
CREATE USER 'username'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost';
FLUSH PRIVILEGES;
-- Create a user with specific privileges
CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'AppPassword123!';
GRANT SELECT, INSERT, UPDATE, DELETE ON myapp.* TO 'app_user'@'localhost';
FLUSH PRIVILEGES;Configuring Remote Access
-- Allow remote connections
CREATE USER 'remote_user'@'%' IDENTIFIED BY 'RemotePassword123!';
GRANT ALL PRIVILEGES ON *.* TO 'remote_user'@'%';
FLUSH PRIVILEGES;
-- Exit MySQL and edit configuration
-- In my.cnf or my.ini
[mysqld]
bind-address = 0.0.0.0Configuration File Location
| Platform |---------------|----------------| | Windows | C:\ProgramData\MySQL\MySQL Server 8.0\my.ini | | macOS | /etc/my.cnf or /usr/local/etc/my.cnf | | Linux (Ubuntu/Debian) | /etc/mysql/mysql.conf.d/mysqld.cnf | | Linux (CentOS/RHEL) | /etc/my.cnf |
Docker Installation
Install Docker
Windows / macOS
- Download Docker Desktop from https://www.docker.com/products/docker-desktop
- Install and start Docker Desktop
Linux
# Ubuntu
sudo apt install docker.io docker-compose
sudo systemctl start docker
sudo systemctl enable docker
# Add user to docker group
sudo usermod -aG docker $USERRun MySQL with Docker
# Pull MySQL image
docker pull mysql:8.0
# Run MySQL container
docker run --name mysql-dev \
-e MYSQL_ROOT_PASSWORD=my-secret-pw \
-p 3306:3306 \
-v mysql_data:/var/lib/mysql \
-d mysql:8.0
# View running containers
docker ps
# Connect to MySQL
docker exec -it mysql-dev mysql -u root -p
# Stop container
docker stop mysql-dev
# Start container
docker start mysql-dev
# Remove container
docker rm mysql-devDocker Compose / Docker Compose
Create docker-compose.yml:
version: '3.8'
services:
mysql:
image: mysql:8.0
container_name: mysql-dev
environment:
MYSQL_ROOT_PASSWORD: my-secret-pw
MYSQL_DATABASE: myapp
MYSQL_USER: appuser
MYSQL_PASSWORD: apppassword
ports:
- "3306:3306"
volumes:
- mysql_data:/var/lib/mysql
restart: always
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 5
volumes:
mysql_data:Run with:
docker-compose up -d
docker-compose downTroubleshooting
Common Installation Issues
MySQL Service Won't Start
# Check error logs
sudo tail -f /var/log/mysql/error.log
# Check port availability
sudo netstat -tlnp | grep 3306
# Try starting with different configuration
sudo mysqld --defaults-file=/etc/my.cnf --user=mysqlAccess Denied Errors
# Reset root password
# Stop MySQL service
sudo systemctl stop mysql
# Start MySQL in safe mode
sudo mysqld_safe --skip-grant-tables &
# Connect and reset password
mysql -u root
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword123!';Port Already in Use
# Find process using port 3306
sudo lsof -i :3306
# Change MySQL port in my.cnf
[mysqld]
port = 3307Check MySQL Logs
# Error log locations
Windows: C:\ProgramData\MySQL\MySQL Server 8.0\Data\*.err
Linux: /var/log/mysql/error.log
macOS: /usr/local/mysql/data/*.err
# View logs
sudo tail -f /var/log/mysql/error.logUninstallation
Windows
- Use Control Panel > Programs and Features
- Find MySQL and click "Uninstall"
- Use MySQL Installer to remove all components
- Delete remaining files manually
macOS
# Stop and remove service
brew services stop mysql@8.0
brew uninstall mysql@8.0
# Remove files
sudo rm -rf /usr/local/var/mysql
sudo rm -rf /usr/local/etc/my.cnfLinux
# Ubuntu/Debian
sudo apt remove mysql-server mysql-client
sudo apt autoremove
sudo rm -rf /var/lib/mysql
sudo rm -rf /etc/mysql
# CentOS/RHEL
sudo dnf remove mysql-community-server mysql-community-client
sudo rm -rf /var/lib/mysql
sudo rm -rf /etc/my.cnfSummary
MySQL installation varies by platform:
- Windows: Use MySQL Installer for easy setup
- macOS: Use Homebrew or DMG package
- Linux: Use package manager (apt, dnf, yum)
- Cross-platform: Use Docker for consistent environment
Key steps after installation:
- Secure installation - Run mysql_secure_installation
- Set root password - Create a strong password
- Create users - Create users with appropriate privileges
- Configure remote access - If needed
- Backup configuration - Keep configuration files safe
Next Steps
Continue to MySQL Administration to learn how to manage and configure MySQL server.
Previous: Introduction
Next: Administration