Support Online
Skip to main content

Guide to Learning MySQL 5.7 Installation, Security Configuration and User Authorization Steps on Ubuntu 18.04

Installing MySQL: Guide to MySQL 5.7 on Ubuntu 18.04

Meta Description: Quickly learn the MySQL 5.7 installation, security configuration and user authorization steps on Ubuntu 18.04 server.

What will you learn in this guide?

In this guide, you will learn step by step how to install MySQL 5.7 on Ubuntu 18.04.
We will configure the security settings after installation.
We will cover root access and user authorization.


Technical Summary

This guide describes the installation of MySQL 5.7 database server on Ubuntu 18.04 system.
Period; It covers package updating, installation, security script execution and user settings.
MySQL is one of the core components of the LAMP (Linux, Apache, MySQL, PHP) architecture.


Prerequisites

  • A Linux server with Ubuntu 18.04
  • sudo authorized user
  • Firewall must be active

Note: Ubuntu 18.04 no longer receives security updates.


MySQL 5.7 Installation

Update package list:

sudo apt update

1️⃣ Installing MySQL Server

To install MySQL server:

sudo apt install mysql-server

This command installs MySQL version 5.7.

Start the service:

sudo systemctl start mysql.service

This command runs the database service.


2️⃣ MySQL Security Configuration

The default installation is not secure.

sudo mysql_secure_installation

This command starts the security wizard.

At this stage:

  • You can activate the password verification plugin\
  • You can set a strong password for root\
  • You can delete anonymous users\
  • You can remove the test database\
  • You can turn off remote root access

It is generally safe to answer Y to all questions.


3️⃣ Changing Root Authentication Method (Optional)

In Ubuntu, the root user logs in using auth_socket by default.
Tools like phpMyAdmin may require password authentication.

Open the MySQL shell:

sudo mysql

This command opens the MySQL administration screen.

Change the root login method:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'GucluParola123!';

This command sets the root account to log in with a password.

Renew authorizations:

FLUSH PRIVILEGES;

This command activates the changes.

Sign out:

exit

4️⃣ Creating a New Database User

It is safer to use a special user instead of root.

CREATE USER 'genix_user'@'localhost' IDENTIFIED BY 'GucluSifre!';

This command creates a new user.

GRANT ALL PRIVILEGES ON *.* TO 'genix_user'@'localhost' WITH GRANT OPTION;

This command gives full permissions to the user.


5️⃣ Testing MySQL Service

Check service status:

systemctl status mysql.service

This command shows the service status.

Check version:

sudo mysqladmin -p -u root version

This command shows MySQL version information.


Frequently Asked Questions (FAQ)

1) How do I know if the MySQL service is running?

You can use the systemctl status mysql.service command.

2) I get the error "Can't create directory '/var/lib/mysql'".

The data directory may have already been created. In Debian-based installations, this is done automatically.

3) How do I turn off remote root access?

Answer Y to the relevant question during mysql_secure_installation.

4) I forgot my root password, what should I do?

You can reset the password by starting MySQL with the parameter --skip-grant-tables.

5) Should I use separate user instead of root?

Yes. Recommended for security reasons.


Result

In this guide, you have installed MySQL on Ubuntu 18.04.
You have completed the basic security configuration.
You learned the user and authorization settings.