Support Online
Skip to main content

MySQL Installation and Security Configuration on Ubuntu (Step by Step)

What will you learn in this guide?

In this guide, MySQL 8.0 installation on Ubuntu 20.04 and above systems,
Solving the auth_socket authentication problem,
You will learn the steps of security configuration and creating a custom user.

🧠 Technical Summary

Subject: Installing and securing MySQL 8.0 on Ubuntu
Problem: Default MySQL installation is not secure and auth_socket loop error
Steps: Setup → Security → Create user → Authorization → Testing


What is MySQL?

MySQL is an open source relational database management system.
It is one of the most basic components of the LAMP architecture.


Prerequisites

  • Ubuntu 20.04 or above
  • User with authority sudo
  • UFW firewall must be configured

1. MySQL Installation

Update package list

sudo apt update
  • This command updates the system package list.

Install MySQL Server


sudo apt install mysql-server
  • This command installs the MySQL 8.0 package.

Start the service


sudo systemctl start mysql.service
  • This command runs the MySQL service.

2. MySQL Security Configuration

  1. On Ubuntu, the MySQL root user is authenticated with auth_socket by default.
  • This may cause an error loop during mysql_secure_installation.

Preventing error loop

  1. Enter the MySQL console

sudo mysql
  • Temporarily set root user with password


ALTER USER 'root'@'localhost'
IDENTIFIED WITH mysql_native_password BY 'GeciciGucluSifre';

Sign out


exit

Run the security wizard


sudo mysql_secure_installation

Recommended choices:

  1. Validate Password Plugin → Y

  2. Password Policy → STRONG

  3. Anonymous users → Remove

  4. Remote root login → Disable

  5. Test database → Remove

  6. Reload privileges → Yes


  1. Log in with root using password

mysql -u root -p

  • go back to auth_socket method

ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;
exit
  • In this way, you can log in again with sudo mysql.

3. Creating a Custom MySQL User

  1. It is not recommended to use the root user in applications.
  • Open MySQL console

sudo mysql

  1. Create new user

CREATE USER 'genixnode_admin'@'localhost'
IDENTIFIED BY 'GucluBirSifre!';

  1. Delegate

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

- Note: In production, it is safer to grant only necessary permissions.


  1. Update authorizations

FLUSH PRIVILEGES;
exit

4. Testing the Installation

  1. Check service status

systemctl status mysql.service
  • The status must be active (running).

Login test with user


mysql -u genixnode_admin -p
  • Version control

sudo mysqladmin -u genixnode_admin -p version

Frequently Asked Questions (FAQ)

1. Why does MySQL use auth_socket? Ubuntu prefers this to map root access to system users.

2. MariaDB or MySQL? MariaDB is community-focused, MySQL has the broader enterprise ecosystem.

3. MySQL service does not start, what should I do? Check /var/log/mysql/error.log file.

4. What if I want to completely uninstall MySQL?


sudo apt purge mysql-server mysql-client mysql-common

Result

With this guide, you have installed a safe, stable and production-ready MySQL on Ubuntu.

For higher performance and scalability, you can immediately try MySQL compatible VDS solutions on the GenixNode infrastructure.