Skip to main content
Rino Puji Blog

Hanya sebuah blog untuk mengisi masa lapang

Install mysql on Ubuntu Server

Info :

  • Post update on 2025/08/26
  • This guideline is for mysql version on Ubuntu 20.04 LTS

Content Shortcut

  1. Installing required package
  2. Mysql Configuration
  3. Creating dedicate User


1.Installing required package

Update package on our ubuntu

$ sudo apt update

Install mysql server

$ sudo apt install mysql-server



2. Mysql Configuration

For running mysql_secure_installation, we need to set mysql password first.

Run mysql as root

$ sudo mysql

And run this command for set the mysql root password.Set the password to your desire and this is only temporary.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Exit from mysql (if you are still there) and run mysql_secure_installation script

$ exit
$ sudo mysql_secure_installation

It will asking for password.The password is password we set early.When the script running,make sure we disable root remote login and remove test database.

Now when the script for secure mysql installation is done,its time for change back our root password to auth_socket back. We will enter mysql again and if prompt asking a password just enter the password we set early.

$ mysql -u root -p

Once we enter mysql,run this command to revert back to auth_socket

mysql > ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;

Now exit mysql,

mysql > exit

Try running it again without password

$ sudo mysql

Check mysql status :

$ systemctl status mysql.service

Check overall machine usage :

$ htop



3. Creating dedicate User

Do not ever use root user for our production,instead create a dedicate user and adjust the permission manually later.

$ sudo mysql

And run this command,change username and password with your desired username and password.

$ CREATE USER 'sammy'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';