MySQL Installation and Setup

Before writing any SQL queries, MySQL must be installed on the system. This topic covers how to install MySQL on Windows, provides an overview for other platforms, and explains how to connect to the MySQL server for the first time.

What Gets Installed

When MySQL is installed, two main components are set up:

  • MySQL Server — The core software that stores and manages databases.
  • MySQL Client — A tool used to communicate with the server. The most common one is the MySQL Command Line Client.

An optional graphical tool called MySQL Workbench is also available. It provides a visual interface for managing databases without typing commands manually.

Installing MySQL on Windows

Step 1: Download the Installer

Go to the official MySQL website: https://dev.mysql.com/downloads/installer/

Download the MySQL Installer for Windows. Choose the larger offline installer for a complete setup.

Step 2: Run the Installer

Double-click the downloaded file to start the installation. When prompted to choose a setup type, select Developer Default for a full installation that includes the server, client tools, and MySQL Workbench.

Step 3: Configure the Server

During setup, the installer will ask for configuration options:

  • Config Type — Choose "Development Computer" for a local development setup.
  • Port — The default port is 3306. Leave it as is unless there is a conflict.
  • Root Password — Set a strong password for the root (admin) user. This password is important — keep it safe.

Step 4: Complete Installation

Click through the remaining steps and let the installer finish. MySQL Server will start automatically after installation.

Installing MySQL on macOS

Download the DMG package from https://dev.mysql.com/downloads/mysql/. Run the installer, set the root password when prompted, and start the MySQL server from System Preferences.

Installing MySQL on Linux (Ubuntu/Debian)

Open the terminal and run the following commands:

sudo apt update
sudo apt install mysql-server
sudo mysql_secure_installation

The mysql_secure_installation command guides through setting a root password and securing the installation.

Verifying the Installation

To confirm MySQL is installed and running, open the Command Prompt (Windows) or Terminal (macOS/Linux) and type:

mysql --version

This displays the installed MySQL version, for example:

mysql  Ver 8.0.33 Distrib 8.0.33, for Win64 (x86_64)

Connecting to MySQL Server

To connect to the MySQL server using the command line, type:

mysql -u root -p

Breaking this down:

  • mysql — Launches the MySQL client.
  • -u root — Connects as the user named "root" (the default admin user).
  • -p — Prompts for a password.

After entering the correct password, the MySQL prompt appears:

mysql>

This means the connection is successful and SQL commands can be entered.

Using MySQL Workbench (Optional)

MySQL Workbench is a visual tool that allows database management without typing commands. After opening it:

  1. Click on the local MySQL connection (usually listed as "Local instance MySQL80").
  2. Enter the root password.
  3. The Workbench interface opens with a query editor on the right and a database panel on the left.

Basic Commands After Login

Once connected to MySQL, these basic commands help get started:

-- Show all existing databases
SHOW DATABASES;

-- Exit the MySQL shell
EXIT;

Key Points

  • MySQL can be installed on Windows, macOS, and Linux.
  • The default port for MySQL is 3306.
  • The root user is the administrator account created during setup.
  • Use mysql -u root -p to connect to the server from the command line.
  • MySQL Workbench provides a graphical alternative to the command line.

Leave a Comment

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