Skip to main content

MySQL Installation

If you already have a local installation of MySQL running on your machine, you can skip this section.

Setting up MySQL on Mac using Brew

This guide will walk you through the process of setting up Postgres on a Macbook using Brew. For other methods please see the MySQL Documentation

Prerequisites

Before proceeding with this guide, ensure that you have the following prerequisites:

  • A Macbook with MacOS installed
  • A working internet connection
  • Basic knowledge of using the terminal

Installation

  1. Open Terminal on your Macbook.

  2. Install Homebrew package manager by running the following command in your terminal:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  3. Once Homebrew is installed, use the following command to install MySQL:

    brew install mysql

This will download and install MySQL and its dependencies.

  1. After installation, start the MySQL service by running the following command:

    brew services start mysql

This will start the MySQL service and ensure that it starts automatically on boot.

Setting up the MySQL Root User

  1. Open Terminal and type the following command to access the MySQL command line interface:

    mysql -u root
  2. Once you are in the MySQL command line interface, type the following command to set the root user's password:

    ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpassword';

Replace yourpassword with your desired password.

  1. Once the password is set, you can exit the MySQL command line interface by typing:

    exit

Congratulations! You have now successfully installed MySQL on your Mac and set up the root user.

Setting up MySQL on Windows

Prerequisites

Before proceeding with this guide, ensure that you have the following prerequisites:

  • A Windows computer running Windows 7 or later
  • A working internet connection
  • Administrator access to the computer
  • Basic knowledge of using the command prompt

Installation

  1. Download the MySQL installer from the MySQL website.

  2. Double-click the downloaded installer file to begin the installation process.

  3. Select "Developer Default" as the setup type, and then click "Next".

  4. On the "MySQL Server Configuration" screen, select "Standalone MySQL Server / Classic MySQL Replication", and then click "Next".

  5. On the "Type and Networking" screen, select "Config Type: Development Machine" and "Check the box for: "Enable TCP/IP Networking". Leave the port number as the default 3306. Then click "Next".

  6. On the "Authentication Method" screen, select "Use Legacy Authentication Method (Retain MySQL 5.x Compatibility)" and set a password for the root user. Then click "Next".

  7. On the "Accounts and Roles" screen, leave the default options as they are, and then click "Next".

  8. On the "Windows Service" screen, select "Standard System Account" as the service account, and then click "Next".

  9. On the "Apply Server Configuration" screen, click "Execute".

  10. Once the installation process is complete, click "Finish".

  11. Open the Command Prompt and type the following command to start the MySQL server:

    net start mysql

    This will start the MySQL server.

  12. To verify that MySQL is installed and working correctly, type the following command:

    mysql -u root -p

    You will be prompted to enter the root user's password that you set during the installation process.

    If everything is working correctly, you should see the MySQL command prompt.

Congratulations! You have now successfully installed MySQL on your Windows computer.

Installing MySQL on Linux

Prerequisites

Before proceeding with this guide, ensure that you have the following prerequisites:

  • A Linux computer running a supported distribution. For a comprehensive list of the supported platforms please see the MySQL docs
  • A working internet connection
  • Administrator access to the computer
  • Basic knowledge of using the command line

Installation

The installation process for MySQL varies depending on your Linux distribution. Here are the installation instructions for some popular distributions:

Ubuntu and Debian

  1. Open a terminal window.

  2. Update the package list by running the following command:

    sudo apt-get update
  3. Install MySQL by running the following command:

    sudo apt-get install mysql-server
  4. During the installation process, you will be prompted to set a password for the MySQL root user.

  5. Once the installation process is complete, the MySQL service should start automatically. You can verify that the service is running by running the following command:

    sudo systemctl status mysql

CentOS and Fedora

  1. Open a terminal window.

  2. Install MySQL by running the following command:

    sudo dnf install mysql-server
  3. During the installation process, you will be prompted to set a password for the MySQL root user.

  4. Once the installation process is complete, start the MySQL service by running the following command:

    sudo systemctl start mysqld
  5. You can verify that the service is running by running the following command:

    sudo systemctl status mysqld

Setting up the MySQL User

  1. Open a terminal window.

  2. Log in to the MySQL server as the root user by running the following command:

    sudo mysql -u root -p
  3. Type in the password you set for the MySQL root user during the installation process.

  4. Once you are logged in to the MySQL server, run the following command to create a new MySQL user:

    CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';

Replace username with the desired username and password with the desired password.

  1. Grant the new user all privileges by running the following command:

    GRANT ALL PRIVILEGES ON . TO 'username'@'localhost';

Replace username with the username you created in step 4.

  1. Once the user is created and granted privileges, exit the MySQL server by running the following command:

    exit

Congratulations! You have now successfully installed MySQL on your Linux computer and created a new MySQL user.