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)"
Once you have Homebrew installed, you can install MySQL by running the command
brew install mysql
After the installation is complete, you can start the MySQL server by running the following command:
brew services start mysql
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
You can now access MySQL by running the following command:
mysql -u root -p
DMG Package
- Download MySQL Community Server: go to the official MySQL website and download the corresponding DMG Archive for your macOS system.
- 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.
- 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
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:
- Update Package Lists: open a terminal on your Ubuntu system and run the following command to update the package lists:
sudo apt update
- Install MySQL Server: run the following command to install the MySQL Server package:
sudo apt install mysql-server
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.
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
- Verify MySQL Installation: to verify if the MySQL server is running correctly, run:
sudo service mysql status
If the service is active and running, it means MySQL is installed and running properly.
- 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
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:
- Update Package Lists: open a terminal on your CentOS system and run the following command to update the package lists.
sudo yum update
- Install MySQL Server: run the following command to install the MySQL Server package:
sudo yum install mysql-server
- Start MySQL Service: after the installation is complete, start the MySQL service by running the following command:
sudo systemctl start mysqld
- 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
Note down the temporary password as you will need it for the next step.
- Run MySQL Secure Installation: to secure your MySQL installation, run the following command and follow the prompts:
sudo mysql_secure_installation
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.
- Start MySQL Service on Boot: to ensure that MySQL starts automatically on system boot, run the following command:
sudo systemctl enable mysqld
Verify MySQL Installation: to verify if the MySQL server is running correctly, you can run the following command:
sudo systemctl status mysqld
If the service is active and running, it means MySQL is installed and running properly.
Windows
To install MySQL locally on Windows:
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).
Run the MySQL Installer: once the download is complete, locate the downloaded installer file and double-click on it to run the MySQL Installer.
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.
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.
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.
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:
-
MySQL Client
mysql
-
MySQL Shell
mysqlsh
introduced in MySQL 8.0 to provide more advanced features overmysql
. - Top MySQL GUI client
- MySQL Schema Compare Tools to Diff and Sync Database
- Top Free Open Source SQL Clients
- Handy mysql Commands with Examples
Top comments (0)