A Step-by-Step Guide to Installing MySQL on Windows, Linux, and macOS

MySQL is one of the most popular relational database management systems used by developers worldwide. Whether you are working on a personal project, a web application, or an enterprise-level solution, setting up MySQL correctly is a crucial first step. This guide will walk you through the installation process for MySQL on three major operating systems: Windows, Linux, and macOS.

Installing MySQL on Windows

To install MySQL on a Windows system, follow these simple steps:

  • Step 1: Visit the official MySQL website at https://dev.mysql.com/downloads/installer/ and download the MySQL Installer for Windows. You can choose either the web installer or the full installer based on your preference.
  • Step 2: Run the downloaded installer file and follow the prompts. You will be asked to choose between a typical installation, which installs the MySQL server and other components, or a custom installation where you can select the components you want to install.
  • Step 3: Select the MySQL Server version and any additional tools you wish to install (e.g., MySQL Workbench or MySQL Shell).
  • Step 4: After installation, configure your MySQL server. You will be prompted to choose a root password and configure other options such as the port number and authentication method.
  • Step 5: Once the installation and configuration are complete, click “Finish” and restart your system if necessary. You can now access MySQL using the command line or MySQL Workbench.

Installing MySQL on Linux

For Linux users, the installation process depends on the distribution you are using. Here, we will cover the installation for two of the most popular Linux distributions: Ubuntu and CentOS.

Installing MySQL on Ubuntu

  • Step 1: Update your package index by running the following command:
    sudo apt-get update

  • Step 2: Install the MySQL server package by running:
    sudo apt-get install mysql-server

  • Step 3: During installation, you will be prompted to set a root password. Make sure to choose a strong password.
  • Step 4: Once installation is complete, start the MySQL service by running:
    sudo systemctl start mysql

  • Step 5: Verify that MySQL is running:
    sudo systemctl status mysql

  • Step 6: Optionally, run the MySQL security script to secure your installation:
    sudo mysql_secure_installation

  • Step 7: You can now log in to MySQL by running:
    sudo mysql -u root -p

Installing MySQL on CentOS

  • Step 1: First, install the MySQL community repository:
    sudo yum install https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

  • Step 2: Install MySQL by running:
    sudo yum install mysql-server

  • Step 3: Start the MySQL service:
    sudo systemctl start mysqld

  • Step 4: Find the temporary root password:
    sudo grep 'temporary password' /var/log/mysqld.log

  • Step 5: Log in to MySQL using the temporary password:
    mysql -u root -p

  • Step 6: Optionally, run the MySQL security script:
    sudo mysql_secure_installation

Installing MySQL on macOS

On macOS, the easiest way to install MySQL is by using Homebrew, a popular package manager for macOS.

  • Step 1: If you don’t have Homebrew installed, install it by running the following command in your terminal:
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

  • Step 2: Once Homebrew is installed, update it and install MySQL with the following commands:
    brew update

    brew install mysql

  • Step 3: After installation, start the MySQL service:
    brew services start mysql

  • Step 4: You can now log in to MySQL:
    mysql -u root

  • Step 5: Optionally, you can secure your MySQL installation by running:
    mysql_secure_installation

Conclusion

By following this guide, you should now have MySQL installed on your system, whether you’re using Windows, Linux, or macOS. MySQL provides a robust and efficient solution for managing databases, and installing it on your system is the first step in leveraging its powerful capabilities. After installation, you can begin creating databases, tables, and queries to build your applications and services.

Leave a Reply

Your email address will not be published. Required fields are marked *