Skip to content

How to Set Up MySQL on Windows Server: A Comprehensive Guide

Introduction

MySQL is a widely-used open-source relational database management system (RDBMS) that powers a vast array of applications and websites. Setting up MySQL on a Windows Server allows you to leverage its robust features in a Windows environment, catering to applications that require high performance and scalability. This guide provides a detailed, step-by-step walkthrough to help you install and configure MySQL on a Windows Server.

Prerequisites

Before proceeding with the installation, ensure the following prerequisites are met:

  • Windows Server Version: This guide is applicable for Windows Server 2012 R2, 2016, 2019, and 2022.
  • Administrator Access: You must have administrative privileges on the Windows Server to install and configure MySQL.
  • Internet Connectivity: Required for downloading MySQL installer and updates.

Step 1: Downloading MySQL Installer

  1. Visit the Official Website:

  2. Select the Windows Version:

    • Choose the MySQL Installer for Windows.
  3. Download the Installer:

    • There are two versions:
      • MySQL Installer Web Community (smaller file, downloads components during installation).
      • MySQL Installer Community (full installer, includes all components).
    • For offline installation, download the full installer.
  4. Save the Installer:

    • Save the downloaded .msi file to a location on your server.

Step 2: Running the MySQL Installer

  1. Launch the Installer:

    • Right-click the downloaded .msi file and select Run as administrator.
  2. Accept License Agreement:

    • Read and accept the license terms to proceed.
  3. Choose Setup Type:

    • Developer Default: Installs MySQL server, applications, and documentation.
    • Server Only: Installs only the MySQL server.
    • Client Only: Installs client programs without the server.
    • Full: Installs all components.
    • Custom: Allows you to select specific components.
    • Recommendation: Choose Custom to select only the necessary components.
  4. Select Features:

    • In the Custom Setup window, expand the components and select:
      • MySQL Server (latest version).
      • MySQL Workbench (for GUI management).
      • MySQL Shell (for advanced scripting).
    • Click Next after selecting the desired features.

Step 3: Checking Requirements

  1. Review Installation:

    • The installer checks for required software (e.g., Visual C++ Redistributable).
    • If any prerequisites are missing, the installer provides links to download them.
  2. Install Required Software:

    • Download and install any missing components.
    • After installation, click Check to verify.
  3. Proceed to Installation:

    • Once all requirements are met, click Next.

Step 4: Installing MySQL

  1. Ready to Install:

    • Review the installation summary.
    • Click Execute to begin the installation.
  2. Installation Progress:

    • The installer displays the progress for each component.
    • Wait until all components are installed successfully.
  3. Complete Installation:

    • After installation, click Next to proceed to configuration.

Step 5: Configuring MySQL Server

  1. Type and Networking:

    • Config Type: Select Development Machine, Server Machine, or Dedicated Machine based on your server's role.
    • Connectivity:
      • TCP/IP Protocol: Enabled.
      • Port Number: Default is 3306. Ensure this port is open in your firewall.
      • Open Firewall Port: Check this option to allow external connections.
  2. Authentication Method:

    • Choose the authentication method:
      • Use Strong Password Encryption (recommended).
      • Use Legacy Authentication Method (for compatibility with older clients).
  3. Accounts and Roles:

    • Root Password:
      • Enter and confirm a strong password for the root user.
      • Keep this password secure.
    • Create User Accounts:
      • Optionally, add additional MySQL user accounts.
      • Specify username, hostname, and password.
  4. Windows Service:

    • Configure MySQL Server as a Windows Service:
      • Check this option to run MySQL as a service.
    • Service Name: Default is MySQL80 (for MySQL 8.0).
    • Start the MySQL Server at System Startup: Enabled.
    • Run Windows Service as:
      • Standard System Account (recommended).
      • Custom User: Specify a Windows user account.
  5. Plugins and Extensions:

    • Optionally, configure plugins like InnoDB Cluster.
    • For basic setup, you can skip this step.
  6. Apply Configuration:

    • Review the configuration settings.
    • Click Execute to apply the configuration.
    • Wait until all configuration steps are completed.
  7. Finish Configuration:

    • Click Finish to complete the configuration process.

Step 6: Testing the MySQL Installation

  1. Open Command Prompt:

    • Press Win + R, type cmd, and press Enter.
  2. Access MySQL Client:

    • Navigate to the MySQL bin directory or ensure it's in your system's PATH.
    • Alternatively, use the full path:
      "C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql" -u root -p
  3. Log In to MySQL:

    • Enter the root password when prompted.
    • Upon successful login, you will see the MySQL prompt: mysql>.
  4. Run a Test Query:

    • Execute:
      sql
      SHOW DATABASES;
    • You should see a list of default databases.
  5. Exit MySQL Client:

    • Type EXIT; and press Enter.

Step 7: Setting Up Environment Variables (Optional)

  1. Access System Properties:

    • Right-click This PC and select Properties.
    • Click Advanced system settings.
  2. Edit Environment Variables:

    • Click Environment Variables.
    • Under System Variables, find and select Path.
    • Click Edit.
  3. Add MySQL Bin Directory to Path:

    • Click New.
    • Add the path to the MySQL bin directory:
      C:\Program Files\MySQL\MySQL Server 8.0\bin
    • Click OK to save changes.
  4. Verify Environment Variable:

    • Open a new command prompt.
    • Type mysql --version to confirm MySQL is recognized.

Step 8: Securing MySQL Installation

While the installer sets up initial security configurations, it's prudent to run the mysql_secure_installation script for additional security measures.

  1. Run Security Script:

    • Open Command Prompt as administrator.
    • Execute:
      mysql_secure_installation
  2. Follow Prompts:

    • Set Root Password: Already set; you can choose to change it.
    • Remove Anonymous Users: Recommended to remove.
    • Disallow Root Login Remotely: Depends on your needs; disabling enhances security.
    • Remove Test Database: Recommended to remove.
    • Reload Privilege Tables: Yes.

Step 9: Connecting to MySQL Using MySQL Workbench

  1. Launch MySQL Workbench:

    • Find MySQL Workbench in the Start Menu and open it.
  2. Create a New Connection:

    • Click the + icon next to MySQL Connections.
  3. Configure Connection:

    • Connection Name: Enter a name (e.g., Local MySQL Server).
    • Hostname: localhost.
    • Port: 3306.
    • Username: root.
    • Password: Click Store in Vault... and enter the root password.
  4. Test Connection:

    • Click Test Connection.
    • If successful, click OK.
  5. Connect to the Server:

    • Double-click the connection to open it.
    • You can now manage databases, run queries, and perform administrative tasks.

Step 10: Configuring Firewall Settings

  1. Open Windows Defender Firewall:

    • Go to Control Panel > System and Security > Windows Defender Firewall.
  2. Allow an App Through Firewall:

    • Click Allow an app or feature through Windows Defender Firewall.
  3. Add MySQL to Allowed Apps:

    • Click Change settings.
    • Click Allow another app....
    • Browse to C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe.
    • Add the app and ensure both Private and Public networks are checked.
  4. Configure Inbound Rules:

    • Alternatively, create a new inbound rule to allow traffic on port 3306.

Step 11: Scheduling Regular Backups

  1. Create Backup Script:

    • Use mysqldump to create a backup script.
      bat
      mysqldump -u root -p[password] --all-databases > "C:\Backups\all_databases.sql"
    • Replace [password] with your root password or omit -p[password] to be prompted.
  2. Schedule Task:

    • Open Task Scheduler.
    • Create a new task to run the backup script at desired intervals.
  3. Verify Backups:

    • Ensure backups are created successfully and stored securely.

Step 12: Updating MySQL

  1. Check for Updates:

  2. Backup Before Updating:

    • Always back up your databases before performing an update.
  3. Run MySQL Installer:

    • Launch the MySQL Installer from the Start Menu.
    • It will detect installed products and offer updates if available.
  4. Follow Update Prompts:

    • Select the products to update and proceed with the installation.

Conclusion

Setting up MySQL on a Windows Server involves careful installation and configuration to ensure a secure and efficient database environment. By following this comprehensive guide, you have successfully installed MySQL, secured the installation, and are ready to manage your databases. Regular maintenance, including backups and updates, will help keep your MySQL server running smoothly.


Note: Always ensure that your MySQL server is secured properly, especially if it's accessible over a network. Use strong passwords, restrict user privileges, and keep your software up to date to protect against vulnerabilities.