Installation
Use this lesson to understand Installation with practical syntax and examples.
Windows Installation
Method 1: MySQL Installer (Recommended)
-
Download the installer:
- Visit https://dev.mysql.com/downloads/installer/
- Choose "Windows (x86, 32 & 64-bit), MySQL Installer MSI"
-
Run the installer:
- Choose setup type: Developer Default (includes MySQL Server + Workbench)
- Follow prompts to install prerequisites
- Configure authentication method:
- Use Strong Password Encryption (Recommended)
- Use Legacy Authentication (If needed for older apps)
- Set root password and create user if desired
- Configure Windows Service:
- Default service name:
MySQL80 - Start server at system boot
- Default service name:
-
Verify installation:
mysql --version- Should return:
mysql Ver 8.0.x for Win64 on x86_64
- Should return:
Method 2: Chocolatey (Package Manager)
-
Install Chocolatey (if not installed):
@"%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('<https://chocolatey.org/install.ps1>'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\\chocolatey\\bin" -
Install MySQL:
choco install mysql
macOS Installation
Method 1: Homebrew (Recommended)
-
Install Homebrew (if not installed):
/bin/bash -c "$(curl -fsSL <https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh>)" -
Install MySQL:
brew install mysql -
Start MySQL service:
brew services start mysql -
Secure installation:
mysql_secure_installation
Method 2: DMG Package
-
Download package:
- Visit https://dev.mysql.com/downloads/mysql/
- Choose macOS version (ARM or x86)
-
Install:
- Double-click DMG file
- Run the installer package
- Choose "Use Strong Password Encryption"
- Note temporary root password
-
Verify:
mysql -u root -p
Linux Installation
Ubuntu/Debian
-
Update package index:
sudo apt update -
Install MySQL Server:
sudo apt install mysql-server -
Secure installation:
sudo mysql_secure_installation -
Check status:
sudo systemctl status mysql
CentOS/RHEL
-
Add MySQL repository:
sudo yum install <https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm> -
Install MySQL Server:
sudo yum install mysql-community-server -
Start service:
sudo systemctl start mysqld
sudo systemctl enable mysqld -
Get temporary password:
sudo grep 'temporary password' /var/log/mysqld.log
Post-Installation Setup for All Systems
-
Connect to MySQL:
mysql -u root -p -
Change root password (if needed):
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewSecurePassword123!'; -
Create test database:
CREATE DATABASE testdb;
USE testdb;
CREATE TABLE users (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50));
INSERT INTO users (name) VALUES ('Test User');
SELECT * FROM users;
Installing MySQL Workbench
Windows
- Included in MySQL Installer package
macOS
brew install --cask mysqlworkbench
Linux
sudo apt install mysql-workbench-community # Ubuntu/Debian
sudo yum install mysql-workbench-community # CentOS/RHEL
Common Installation Issues
Windows:
Can't connect to MySQL servererror- Check MySQL service is running (Services -> MySQL80)
macOS:
Command not found: mysql- Add to PATH:
echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.zshrc
- Add to PATH:
Linux:
- Socket error
/var/run/mysqld/mysqld.sock- Create directory:
sudo mkdir -p /var/run/mysqld && sudo chown mysql:mysql /var/run/mysqld
- Create directory:
Configuration Files Location
| OS | File Location |
|---|---|
| Windows | C:\\ProgramData\\MySQL\\MySQL Server 8.0\\my.ini |
| Linux | /etc/mysql/my.cnf |
| macOS | /usr/local/etc/my.cnf |
Uninstallation Guides
Windows:
- Control Panel -> Uninstall Programs
- Remove MySQL entries
- Delete
C:\\Program Files\\MySQL
macOS:
brew services stop mysql
brew uninstall mysql
sudo rm -rf /usr/local/var/mysql
Ubuntu:
sudo apt purge mysql-server mysql-client mysql-common
sudo rm -rf /etc/mysql /var/lib/mysql
Next Steps After Installation
-
Create a non-root user:
CREATE USER 'admin'@'localhost' IDENTIFIED BY 'SecurePass123!';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost'; -
Test remote connection (if needed):
UPDATE mysql.user SET host='%' WHERE user='admin';
FLUSH PRIVILEGES; -
Configure firewall:
sudo ufw allow 3306/tcp # Linux
Version Check & Updates
Check installed version:
SELECT VERSION();
Update MySQL (Linux example):
sudo apt update && sudo apt upgrade mysql-server
You're now ready to start working with MySQL! Next we'll cover basic SQL operations and database management.
Concept Map
flowchart LR
A[Schema Context] --> B[Installation]
B --> C[Query Pattern]
C --> D[Validation]
D --> E[Production Use]
Common Pitfalls
| Pitfall | Consequence | Prevention |
|---|---|---|
| Executing queries without validating sample rows | Logic errors reach production data or reports | Start with SELECT ... LIMIT 10 and inspect edge cases |
| Ignoring NULL and duplicate behavior | Aggregations and filters return misleading results | Test with NULL, duplicates, and empty sets explicitly |
| Using advanced syntax before checking schema | Queries fail due to missing columns/indexes | Verify structure with DESCRIBE table_name; and adapt query design |
Quick Reference
# Check client and server availability
mysql --version
systemctl status mysql
# Open MySQL shell
mysql -u root -p
What's Next
- Next: Mysql workbench - Continue to the next concept with incremental complexity.
- Module Overview - Return to this module index and choose another related lesson.