Lesson 6 of 60 – MySQL Installation
10%

MySQL Installation

Before working with MySQL, you need to install a MySQL server and a tool for writing and executing SQL queries. In this lesson, you will learn the basic installation process and the important components used when setting up MySQL.

Note: MySQL can be installed on operating systems such as Windows, Linux, and macOS. The exact installation screens can vary depending on the operating system and MySQL version.

1. What is MySQL Installation?

MySQL installation means setting up the MySQL software on your computer so that you can create databases, tables, and execute SQL queries.

A typical MySQL setup includes a server and client tools.

2. MySQL Server

The MySQL Server is the main component that stores and manages databases.

Applications and database tools connect to the server to perform database operations.

Application
     ↓
MySQL Client
     ↓
MySQL Server
     ↓
Database

3. MySQL Client

A MySQL client is a program that connects to the MySQL server.

It allows users or applications to send SQL statements to the server.

Examples include MySQL Workbench and the MySQL command-line client.

4. MySQL Installer

On supported Windows setups, the MySQL Installer can be used to install and configure MySQL products.

It can help install components such as the MySQL Server, Workbench, Shell, and other tools depending on the selected setup.

5. Downloading MySQL

MySQL should be downloaded from the official MySQL website.

Choose the installer or package appropriate for your operating system and system architecture.

Always check the requirements for the MySQL version you plan to install.

6. MySQL on Windows

On Windows, MySQL can be installed using the MySQL Installer or other official installation packages.

The installer provides a guided process for selecting MySQL components and configuring the server.

7. MySQL on Linux

On Linux, MySQL can be installed using packages and package-management tools appropriate for the Linux distribution.

The exact commands depend on the distribution and repository configuration.

8. MySQL on macOS

MySQL can also be installed on macOS using the installation methods provided for the platform.

After installation, the MySQL server can be started and configured for local development.

9. Choosing Installation Components

Depending on your requirements, you may install different MySQL components.

  • MySQL Server
  • MySQL Workbench
  • MySQL Shell
  • MySQL client tools

10. MySQL Server Configuration

During installation, the MySQL Server may require configuration settings.

These can include networking, authentication, and server-related settings.

The exact options depend on the MySQL version and installation method.

11. MySQL Server Port

MySQL uses a network port for client-server communication.

The traditional default port for MySQL is 3306.

MySQL Server
Port: 3306

If another application is already using the port, the configuration may need to be changed.

12. Root User

During MySQL setup, an administrative account such as root can be configured.

The root account has powerful database privileges, so its password should be protected carefully.

13. Setting a Strong Password

Use a strong password for administrative MySQL accounts.

A strong password should not be easy to guess and should not be reused unnecessarily across unrelated services.

Never publish database passwords in public source code.

14. Authentication

MySQL supports authentication mechanisms that control how users prove their identity when connecting to the server.

The available authentication method can depend on the MySQL version and account configuration.

15. Starting MySQL Server

After installation, the MySQL Server needs to be running before clients can normally connect to it.

On many systems, MySQL can be configured to start automatically as a service.

Client
  ↓
Running MySQL Server
  ↓
Database

16. Checking MySQL Server Status

You can check whether the MySQL Server is running using the operating system's service-management tools or MySQL administration tools.

A running server is required for normal client-server database operations.

17. Connecting to MySQL

A MySQL client generally needs connection information such as:

Host
Port
Username
Password

For a local development installation, the host is commonly localhost.

18. Localhost

localhost refers to the computer on which the client or application is running.

A local MySQL development connection may look conceptually like:

Host: localhost
Port: 3306

19. Testing MySQL Connection

After installation, test the connection using MySQL Workbench, MySQL Shell, or another MySQL client.

If the connection succeeds, you can begin creating databases and executing SQL statements.

20. MySQL Command-Line Client

The MySQL command-line client allows you to work with MySQL directly from a terminal or command prompt.

mysql -u root -p

The command requests the password for the specified MySQL user.

21. MySQL Workbench

MySQL Workbench provides a graphical environment for working with MySQL.

It can be used to:

  • Connect to MySQL servers
  • Write SQL queries
  • Create databases and tables
  • Manage database objects
  • View database structures

22. Creating Your First Database

Once the MySQL server is running, you can create a database using SQL.

CREATE DATABASE school;

To use the database:

USE school;

23. Creating Your First Table

After selecting a database, create a table.

CREATE TABLE students (
    id INT PRIMARY KEY,
    name VARCHAR(100),
    course VARCHAR(100)
);

24. Inserting Test Data

You can insert a test record to verify that the database is working correctly.

INSERT INTO students
(id, name, course)
VALUES
(1, 'Rahul', 'Python');

25. Retrieving Test Data

Use SELECT to retrieve the inserted record.

SELECT * FROM students;

If the record appears in the result, the basic database operations are working.

26. Common Installation Problems

Some common installation or connection problems include:

  • MySQL Server is not running
  • Incorrect username or password
  • Port conflict
  • Incorrect host information
  • Firewall or network configuration issues
  • Incomplete installation

27. Port Conflict

If another service is already using the configured MySQL port, the MySQL server may not start correctly on that port.

Check the server configuration and the services running on your computer before changing ports.

28. Security After Installation

After installation, protect your MySQL environment.

  • Use strong passwords.
  • Create separate accounts for applications when appropriate.
  • Grant only the privileges that are required.
  • Keep MySQL updated according to your maintenance policy.
  • Avoid exposing a database server unnecessarily to the public internet.

29. Basic Installation Workflow

1. Download MySQL
2. Install MySQL Server
3. Install Workbench if required
4. Configure the server
5. Set administrator credentials
6. Start MySQL Server
7. Connect using a MySQL client
8. Create a database
9. Create a table
10. Test with SQL queries

30. Complete Installation Example

After successfully installing and connecting to MySQL, you can perform your first complete database operation.

CREATE DATABASE school;

USE school;

CREATE TABLE students (
    id INT PRIMARY KEY,
    name VARCHAR(100),
    course VARCHAR(100)
);

INSERT INTO students
(id, name, course)
VALUES
(1, 'Rahul', 'Python');

SELECT * FROM students;

If the query returns the student record, your basic MySQL environment is ready for practice.

📌 Key Points

  • MySQL Server is the main component that manages databases.
  • MySQL clients connect to the MySQL Server.
  • MySQL Workbench provides a graphical environment for database development and administration.
  • The traditional default MySQL port is 3306.
  • The root account is an administrative account and should be protected carefully.
  • MySQL must be running before normal client-server connections can be made.
  • localhost is commonly used for local development connections.
  • The MySQL command-line client can be used from a terminal.
  • After installation, you can create databases, tables, and test data.
  • Strong passwords and appropriate user privileges are important for security.

🧠 Quick Quiz

Question: What is the traditional default port used by MySQL?