Skip to main content

Installation

Learning Focus

Use this lesson to understand Installation with practical syntax and examples.

Windows Installation

  1. Download the installer:

  2. 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
  3. Verify installation:

    mysql --version

    • Should return: mysql Ver 8.0.x for Win64 on x86_64

Method 2: Chocolatey (Package Manager)

  1. 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"

  2. Install MySQL:

    choco install mysql

macOS Installation

  1. Install Homebrew (if not installed):

    /bin/bash -c "$(curl -fsSL <https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh>)"

  2. Install MySQL:

    brew install mysql

  3. Start MySQL service:

    brew services start mysql

  4. Secure installation:

    mysql_secure_installation

Method 2: DMG Package

  1. Download package:

  2. Install:

    • Double-click DMG file
    • Run the installer package
    • Choose "Use Strong Password Encryption"
    • Note temporary root password
  3. Verify:

    mysql -u root -p

Linux Installation

Ubuntu/Debian

  1. Update package index:

    sudo apt update

  2. Install MySQL Server:

    sudo apt install mysql-server

  3. Secure installation:

    sudo mysql_secure_installation

  4. Check status:

    sudo systemctl status mysql

CentOS/RHEL

  1. Add MySQL repository:

    sudo yum install <https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm>

  2. Install MySQL Server:

    sudo yum install mysql-community-server

  3. Start service:

    sudo systemctl start mysqld
    sudo systemctl enable mysqld

  4. Get temporary password:

    sudo grep 'temporary password' /var/log/mysqld.log

Post-Installation Setup for All Systems

  1. Connect to MySQL:

    mysql -u root -p

  2. Change root password (if needed):

    ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewSecurePassword123!';

  3. 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 server error
    • 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

Linux:

  • Socket error /var/run/mysqld/mysqld.sock
    • Create directory: sudo mkdir -p /var/run/mysqld && sudo chown mysql:mysql /var/run/mysqld

Configuration Files Location

OSFile Location
WindowsC:\\ProgramData\\MySQL\\MySQL Server 8.0\\my.ini
Linux/etc/mysql/my.cnf
macOS/usr/local/etc/my.cnf

Uninstallation Guides

Windows:

  1. Control Panel -> Uninstall Programs
  2. Remove MySQL entries
  3. 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

  1. Create a non-root user:

    CREATE USER 'admin'@'localhost' IDENTIFIED BY 'SecurePass123!';
    GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost';

  2. Test remote connection (if needed):

    UPDATE mysql.user SET host='%' WHERE user='admin';
    FLUSH PRIVILEGES;

  3. 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

PitfallConsequencePrevention
Executing queries without validating sample rowsLogic errors reach production data or reportsStart with SELECT ... LIMIT 10 and inspect edge cases
Ignoring NULL and duplicate behaviorAggregations and filters return misleading resultsTest with NULL, duplicates, and empty sets explicitly
Using advanced syntax before checking schemaQueries fail due to missing columns/indexesVerify 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