DEV Community

Cover image for 🐬How to Install Local MySQL on Your Mac, Ubuntu, CentOS, Windows🚀🦾
Mila Wu for Bytebase

Posted on • Originally published at bytebase.com

🐬How to Install Local MySQL on Your Mac, Ubuntu, CentOS, Windows🚀🦾

Introduction

A local MySQL database is installed and running on your own computer or server, allows developers to work offline without depending on a remote server, and also enables them to quickly iterate on changes without risking data loss or corruption.

Below is a tutorial on how to install a local MySQL database server on your Mac, Ubuntu, CentOS, or Windows.

Info: to interact with your local MySQL database, you can install the classic MySQL CLI.

macOS

GUI

Check out DBngin or StackBricks.

Homebrew

If you don't have Homebrew installed, you can install it by running the following command in your terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode

Once you have Homebrew installed, you can install MySQL by running the command

brew install mysql
Enter fullscreen mode Exit fullscreen mode

After the installation is complete, you can start the MySQL server by running the following command:

brew services start mysql
Enter fullscreen mode Exit fullscreen mode

By default, Homebrew installs the MySQL server without a root password. To secure your installation, you should run the MySQL secure installation script. Run the following command and follow the prompts to set a root password and remove insecure defaults:

mysql_secure_installation
Enter fullscreen mode Exit fullscreen mode

You can now access MySQL by running the following command:

mysql -u root -p
Enter fullscreen mode Exit fullscreen mode

DMG Package

  1. Download MySQL Community Server: go to the official MySQL website and download the corresponding DMG Archive for your macOS system.
  2. Install MySQL Community Server: open the downloaded DMG file and follow the on-screen instructions to install MySQL Community Server. It will guide you through the installation process, including accepting the license agreement, choosing the installation location, and setting a root password for MySQL.
  3. Start MySQL Server: once the installation is complete, you can close the installation window, and the MySQL server should already be up and running. If it doesn't, you can start the MySQL server by running the following command in the Terminal application on your Mac:
mysql -u root -p
Enter fullscreen mode Exit fullscreen mode

It will prompt you to enter the root password you set during the installation. If the MySQL server is running correctly, you will be logged into the MySQL CLI mysql.

Ubuntu

To install MySQL locally on Ubuntu, you need to:

  1. Update Package Lists: open a terminal on your Ubuntu system and run the following command to update the package lists:
sudo apt update
Enter fullscreen mode Exit fullscreen mode
  1. Install MySQL Server: run the following command to install the MySQL Server package:
sudo apt install mysql-server
Enter fullscreen mode Exit fullscreen mode
  1. Configure MySQL Server: during the installation process, you will be prompted to set the root password for the MySQL Server. Enter a secure password and remember it, as you will need it later.

  2. Start MySQL Service: after the installation is complete, MySQL should start automatically. If it doesn't, you can start the MySQL service by running the following command:

sudo service mysql start
Enter fullscreen mode Exit fullscreen mode
  1. Verify MySQL Installation: to verify if the MySQL server is running correctly, run:
sudo service mysql status
Enter fullscreen mode Exit fullscreen mode

If the service is active and running, it means MySQL is installed and running properly.

  1. Secure MySQL Installation (optional): it is recommended to run the MySQL secure installation script to improve the security of your MySQL installation. You can run the following command to start the script:
sudo mysql_secure_installation
Enter fullscreen mode Exit fullscreen mode

The script will guide you through several security-related questions and allow you to set additional security measures.

CentOS

To install MySQL locally on CentOS, follow these steps:

  1. Update Package Lists: open a terminal on your CentOS system and run the following command to update the package lists.
sudo yum update
Enter fullscreen mode Exit fullscreen mode
  1. Install MySQL Server: run the following command to install the MySQL Server package:
sudo yum install mysql-server
Enter fullscreen mode Exit fullscreen mode
  1. Start MySQL Service: after the installation is complete, start the MySQL service by running the following command:
sudo systemctl start mysqld
Enter fullscreen mode Exit fullscreen mode
  1. Configure MySQL Server: the first time you start the MySQL service, it generates a temporary root password. You can retrieve this password by running the following command:
sudo grep 'temporary password' /var/log/mysqld.log
Enter fullscreen mode Exit fullscreen mode

Note down the temporary password as you will need it for the next step.

  1. Run MySQL Secure Installation: to secure your MySQL installation, run the following command and follow the prompts:
sudo mysql_secure_installation
Enter fullscreen mode Exit fullscreen mode

The script will guide you through several security-related questions and allow you to set additional security measures. You will be prompted to enter the temporary root password generated earlier.

  1. Start MySQL Service on Boot: to ensure that MySQL starts automatically on system boot, run the following command:
sudo systemctl enable mysqld
Enter fullscreen mode Exit fullscreen mode

Verify MySQL Installation: to verify if the MySQL server is running correctly, you can run the following command:

sudo systemctl status mysqld
Enter fullscreen mode Exit fullscreen mode

If the service is active and running, it means MySQL is installed and running properly.

Windows

To install MySQL locally on Windows:

  1. Download MySQL Community Server: go to the official MySQL website and download the MySQL Community Server for Windows. Choose the appropriate version based on your system architecture (32-bit or 64-bit).

  2. Run the MySQL Installer: once the download is complete, locate the downloaded installer file and double-click on it to run the MySQL Installer.

  3. Select Setup Type: in the MySQL Installer, select the "Developer Default" setup type. This will install the MySQL Server, MySQL Workbench (a GUI tool for managing MySQL), and other necessary components. Click the "Next" button.

  4. Choose Installation Type: in the "Choose a Setup Type" screen, select the "Server Only" option. This will install only the MySQL Server component. Click the "Next" button.

  5. Configure MySQL Server: on the "Check Requirements" screen, you can choose the installation folder for MySQL Server and configure other server settings. You can also set a root password for the MySQL Server. Click the "Next" button.

  6. Verify MySQL Installation: to verify if the MySQL server is running correctly, open the Windows Start menu, search for "MySQL Command Line Client," and click on it. It will open a command-line interface for MySQL. Enter the root password you set during the installation to log in. If the login is successful, you have successfully installed MySQL locally on your Windows computer.

Last but Not Least

Congratulations! You have successfully installed MySQL locally on your system. You can now start using MySQL for your database-related tasks.

And of course, you will need a few tools to better master and interact with MySQL, for example:

Top comments (1)

Collapse
 
instructa-ai profile image
Instructa

Helpfully