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
Open Terminal on your Macbook.
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)"
Once Homebrew is installed, use the following command to install MySQL:
brew install mysql
This will download and install MySQL and its dependencies.
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
Open Terminal and type the following command to access the MySQL command line interface:
mysql -u root
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.
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
Download the MySQL installer from the MySQL website.
Double-click the downloaded installer file to begin the installation process.
Select "Developer Default" as the setup type, and then click "Next".
On the "MySQL Server Configuration" screen, select "Standalone MySQL Server / Classic MySQL Replication", and then click "Next".
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".
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".
On the "Accounts and Roles" screen, leave the default options as they are, and then click "Next".
On the "Windows Service" screen, select "Standard System Account" as the service account, and then click "Next".
On the "Apply Server Configuration" screen, click "Execute".
Once the installation process is complete, click "Finish".
Open the Command Prompt and type the following command to start the MySQL server:
net start mysql
This will start the MySQL server.
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
Open a terminal window.
Update the package list by running the following command:
sudo apt-get update
Install MySQL by running the following command:
sudo apt-get install mysql-server
During the installation process, you will be prompted to set a password for the MySQL root user.
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
Open a terminal window.
Install MySQL by running the following command:
sudo dnf install mysql-server
During the installation process, you will be prompted to set a password for the MySQL root user.
Once the installation process is complete, start the MySQL service by running the following command:
sudo systemctl start mysqld
You can verify that the service is running by running the following command:
sudo systemctl status mysqld
Setting up the MySQL User
Open a terminal window.
Log in to the MySQL server as the root user by running the following command:
sudo mysql -u root -p
Type in the password you set for the MySQL root user during the installation process.
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.
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.
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.