Logo

How to Install MySQL on Windows Server 2022

How to Install MySQL on Windows Server 2022

This comprehensive guide explains how to install and configure MySQL database server on Windows Server 2022. It covers downloading the MySQL installer, choosing setup types, configuring the server with proper security settings (root password, authentication methods), setting up as a Windows service, configuring the firewall, creating databases and users, and includes best security practices and troubleshooting tips.

How to Install MySQL on Windows Server 2022

MySQL is a free, open-source relational database management system (RDBMS) widely used for web applications, data warehousing, and e-commerce. This comprehensive guide will walk you through installing and configuring MySQL on Windows Server 2022.

What is MySQL?

MySQL is one of the most popular database systems in the world. It's:

  • Free and open-source (Community Edition)
  • Fast and reliable for storing and retrieving data
  • Compatible with many programming languages (PHP, Python, Java, etc.)
  • Widely used by applications like WordPress, Joomla, and Drupal

Prerequisites

Before installing MySQL, ensure you have:

  • Windows Server 2022 (also compatible with 2016, 2019)
  • Administrator privileges
  • At least 2 GB of RAM (4 GB or more recommended)
  • Sufficient disk space (minimum 1 GB free)
  • Internet connection for downloading the installer

Step 1: Download MySQL Installer

Go to the official MySQL downloads page:

https://dev.mysql.com/downloads/installer/

Choose Your Installer Version

MySQL offers two installer options:

1. MySQL Installer Web Community (Recommended for most users)

  • Smaller file size (~2-3 MB)
  • Downloads components during installation
  • Requires internet connection during setup

2. MySQL Installer Community (Full installer)

  • Larger file size (~400-500 MB)
  • Includes all components
  • Works for offline installation

Download the Installer

  1. Click Download next to your preferred installer (32-bit or 64-bit doesn't matter - the installer is 32-bit only)
  2. You'll be redirected to a login/signup page
  3. Click "No thanks, just start my download" at the bottom to skip account creation
  4. Save the .msi file to your server

Step 2: Run MySQL Installer

Launch the Installer

  1. Locate the downloaded .msi file
  2. Right-click on it and select Run as administrator
  3. If prompted by User Account Control (UAC), click Yes

Accept License Agreement

  1. Read the license terms
  2. Check "I accept the license terms"
  3. Click Next

Step 3: Choose Setup Type

You'll be asked to select a setup type. Here are the options:

Setup Type Options

Developer Default

  • Installs MySQL Server, Workbench, Shell, connectors, and documentation
  • Good for development environments
  • ~1 GB disk space required

Server only (Recommended for servers)

  • Installs only the MySQL Server
  • Minimal installation
  • Perfect for production servers
  • ~500 MB disk space required

Client only

  • Installs client tools without the server
  • For connecting to remote MySQL servers

Full

  • Installs all MySQL products
  • ~2 GB disk space required

Custom

  • Lets you choose specific components
  • For advanced users

Recommendation

For a Windows Server 2022, choose "Server only" to install just the MySQL database server.

Click Next after selecting your setup type.

Step 4: Check Requirements

The installer will check for any missing requirements. If everything is okay, click Execute to begin installation.

Installation Process

  1. Click Execute to start downloading and installing MySQL components
  2. Wait for the installation to complete (this may take a few minutes)
  3. When finished, all items will show a green checkmark
  4. Click Next to proceed to configuration

Step 5: Configure MySQL Server

Now comes the configuration part, which is crucial for setting up MySQL properly.

Type and Networking Configuration

Config Type:

  • Development Computer: For personal use with other applications running
  • Server Computer: For servers running multiple applications (Recommended)
  • Dedicated Computer: For servers dedicated only to MySQL

Connectivity:

  • Protocol: TCP/IP (default)
  • Port: 3306 (default) - keep this unless you have a specific reason to change it
  • Open Windows Firewall port: Check this box to allow connections

Click Next to continue.

Authentication Method

You'll be asked to choose an authentication method:

Use Strong Password Encryption (Recommended)

  • Uses the latest authentication method
  • More secure
  • Compatible with MySQL 8.0+ clients

Use Legacy Authentication Method

  • For compatibility with older MySQL clients and applications
  • Choose this if you're using older software that requires it

Recommendation: Use Strong Password Encryption unless you have a specific compatibility requirement.

Click Next.

Accounts and Roles

This is where you set up the MySQL root password.

Root Password:

  1. Enter a strong password for the root user
  2. Confirm the password
  3. Important: Write this password down and keep it safe!

Additional Users (Optional):

  • Click Add User to create additional MySQL users
  • Fill in:
    • User Name: e.g., webapp_user
    • Host: localhost or % (for any host)
    • Role: Select appropriate role (DB Admin, DB Designer, etc.)
    • Password: Set a strong password

Click Next.

Windows Service

Configure MySQL to run as a Windows service:

Settings:

  • Configure MySQL Server as a Windows Service: Check this box
  • Windows Service Name: MySQL80 (or MySQL followed by version number)
  • Start the MySQL Server at System Startup: Check this box (recommended)
  • Run Windows Service as: Standard System Account (recommended)

Click Next.

Apply Configuration

  1. Click Execute to apply all configuration settings
  2. Wait for all configuration steps to complete (green checkmarks)
  3. Click Finish when done

Complete Installation

  1. Click Next on the Product Configuration screen
  2. Click Finish to complete the MySQL installation

Step 6: Verify MySQL Installation

Method 1: Check Windows Service

  1. Press Windows Key + R
  2. Type services.msc and press Enter
  3. Look for MySQL80 (or your service name) in the list
  4. Verify that Status shows Running

Method 2: Using Command Line

Open Command Prompt as Administrator and run:

mysql --version

You should see the MySQL version information.

Method 3: Connect to MySQL

Test the connection to MySQL:

mysql -u root -p

Enter your root password when prompted. If successful, you'll see the MySQL prompt:

mysql>

Type exit to quit MySQL.

Step 7: Configure Windows Firewall

If you need to access MySQL from other computers on your network:

Open Firewall Port

  1. Press Windows Key + R
  2. Type wf.msc and press Enter (Windows Firewall)
  3. Click Inbound Rules in the left panel
  4. Click New Rule in the right panel
  5. Select Port and click Next
  6. Select TCP and enter 3306 in Specific local ports
  7. Click Next
  8. Select Allow the connection
  9. Click Next
  10. Check all profiles (Domain, Private, Public)
  11. Click Next
  12. Enter a name: MySQL Server
  13. Click Finish

Or use PowerShell:

New-NetFirewallRule -DisplayName "MySQL Server" -Direction Inbound -Protocol TCP -LocalPort 3306 -Action Allow

Step 8: Test MySQL Connection

Create Your First Database

Connect to MySQL:

mysql -u root -p

Enter your password, then run:

CREATE DATABASE testdb;
SHOW DATABASES;
USE testdb;

Create a Test Table

CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(50) NOT NULL,
    email VARCHAR(100) NOT NULL
);

SHOW TABLES;

Insert Test Data

INSERT INTO users (username, email) VALUES ('john_doe', '[email protected]');
SELECT * FROM users;

Optional: Install MySQL Workbench

MySQL Workbench is a graphical tool for managing MySQL databases.

If you didn't install it initially:

  1. Run the MySQL Installer again
  2. Click Add on the main screen
  3. Select MySQL Workbench from the list
  4. Click Next and Execute to install

Using MySQL Workbench

  1. Open MySQL Workbench from the Start menu
  2. Click the + icon next to "MySQL Connections"
  3. Enter connection details:
    • Connection Name: Local Server
    • Hostname: localhost
    • Port: 3306
    • Username: root
  4. Click Store in Vault to save the password
  5. Click Test Connection
  6. If successful, click OK
  7. Double-click the connection to manage your databases

Creating Additional MySQL Users

It's a security best practice to create separate users for applications instead of using root:

-- Connect as root
mysql -u root -p

-- Create a new user
CREATE USER 'myapp_user'@'localhost' IDENTIFIED BY 'strong_password';

-- Grant privileges to a specific database
GRANT ALL PRIVILEGES ON myapp_db.* TO 'myapp_user'@'localhost';

-- Apply changes
FLUSH PRIVILEGES;

-- Verify
SHOW GRANTS FOR 'myapp_user'@'localhost';

For Remote Access

To allow connections from other computers:

-- Create user that can connect from any host
CREATE USER 'myapp_user'@'%' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON myapp_db.* TO 'myapp_user'@'%';
FLUSH PRIVILEGES;

Security Best Practices

1. Use Strong Passwords

Always use complex passwords with uppercase, lowercase, numbers, and special characters.

2. Limit Remote Root Access

Never allow root to connect remotely:

DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
FLUSH PRIVILEGES;

3. Remove Anonymous Users

DELETE FROM mysql.user WHERE User='';
FLUSH PRIVILEGES;

4. Remove Test Database

DROP DATABASE IF EXISTS test;
DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';
FLUSH PRIVILEGES;

5. Regular Backups

Always maintain regular backups of your databases.

Troubleshooting

MySQL Service Won't Start

Solution 1: Check the error log

  • Default location: C:\ProgramData\MySQL\MySQL Server 8.0\Data\
  • Look for .err files

Solution 2: Verify configuration

  • Check my.ini file in the MySQL installation directory

Solution 3: Reinstall

  • Uninstall MySQL
  • Delete C:\ProgramData\MySQL folder
  • Reinstall

Cannot Connect to MySQL

Check if service is running:

net start MySQL80

Verify port is listening:

netstat -an | findstr 3306

Forgot Root Password

  1. Stop MySQL service
  2. Start MySQL with skip-grant-tables option
  3. Reset password
  4. Restart MySQL normally

Port 3306 Already in Use

Another application is using port 3306. Either:

  • Change MySQL to use a different port during installation
  • Stop the other application using port 3306

Updating MySQL

To update MySQL to a newer version:

  1. Run the MySQL Installer
  2. Click Upgrade next to MySQL Server
  3. Follow the upgrade wizard
  4. Your data and configurations will be preserved

Uninstalling MySQL

To completely remove MySQL:

  1. Open Control Panel > Programs and Features
  2. Find MySQL Server and click Uninstall
  3. Delete the following folders:
    • C:\Program Files\MySQL
    • C:\ProgramData\MySQL (contains your databases)

Summary

To install MySQL on Windows Server 2022:

  1. Download MySQL Installer from mysql.com
  2. Run installer as Administrator
  3. Choose "Server only" setup type
  4. Configure server (port 3306, root password)
  5. Set as Windows service
  6. Open firewall port 3306 if needed
  7. Test connection with mysql -u root -p

MySQL is now ready to use for your applications!

Join our Discord community server

For any questions, suggestions, or just to chat with the community, join us on Discord!

900+Members