Instalasi MySQL Server

Instalasi MySQL Server di Ubuntu 20.10

Prasyarat

Saya biasanya sebelum melakuan instalasi MySQL aplikasi akan coba update dan upgrade dulu dengan perintah :

sudo apt update
sudo apt upgrade

Langkah 1 : Instalasi

Jika sudah selesai Update dan Upgrade, maka selanjutnya instalasi dengan menjalankan perintah :

sudo apt install mysql-server

Langkah 2 : Mengamankan MySQL Server

Jalankan perintah di bawah ini :

$ sudo mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y

Tekan Tombol y, maka akan ditanya mau seberapa kuat kebijakan pasword yang akan kita terapkan? Pilih saja yang paling kuat dengan menekan angka 2.

There are three levels of password validation policy:
LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2

Kemudian akan diminta memasukan password. Biasanya nya saya menuliskan nya dulu di Notepad agar tidak salah, lalu di copy paste ke terminal. Setelah input password , tekan tombol Y untuk mengaktifkan password yang kita buat

New password:
Re-enter new password:
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y

Secara Default, MySQL menyediakan user anonymous, lebih baik hapus saja :

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y

Kemudian muncul pertanyaan lagi agar user root hanya bisa diakses secara local saja. Tekan tombol Y agar root hanya bisa akses secara lokal

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y

Secara default MySQL mempynyai database bawaan dengan nama test, ini juga sebaiknya dihapus jika tidak digunakan.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y

Selanjutnya muncul pertanyaan untuk mengaktifkan privileges yang sudah dibuat:

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y

Selesai.
Sekarang untuk mencoba nya silahkan login dengan menuliskan perintah :

$ sudo mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 8.0.23-0ubuntu0.20.10.1 (Ubuntu)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Mengapa saat saya menggunakan perintah

mysql -u root -p

lalu memasukan password yang benar, muncul error

ERROR 1698 (28000): Access denied for user ‘root’@’localhost’

Hal diatas dikarenakan MySQL yang baru menggunakan plugin auth_socket untuk authentikasinya. Untuk memastikannya jalankan perintah berikut

mysql> use mysql;
 Reading table information for completion of table and column names
 You can turn off this feature to get a quicker startup with -A
 Database changed
 mysql> SELECT User, Host, plugin FROM mysql.user;
 +------------------+-----------+-----------------------+
 | User             | Host      | plugin                |
 +------------------+-----------+-----------------------+
 | debian-sys-maint | localhost | caching_sha2_password |
 | mysql.infoschema | localhost | caching_sha2_password |
 | mysql.session    | localhost | caching_sha2_password |
 | mysql.sys        | localhost | caching_sha2_password |
 | root             | localhost | auth_socket           |
 +------------------+-----------+-----------------------+
 5 rows in set (0.00 sec)

Terlihat user root menggunakan plugin auth_socket. Bagaimana cara mengembalikan seperti biasa untuk login nya ? Jalankan beberapa perintah berikut :

mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'isipassword';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit;
Bye

Restart Service MySQL nya

sudo service mysql restart

Coba jalankan perintah :

mysql -u root -p

Lalu masukan password yang tadi ‘isipassword’.

1 thought on “Instalasi MySQL Server di Ubuntu 20.10”

  1. Pingback: Install phpMyAdmin di Nginx Ubuntu 20.10 Server - Stelselmatig

Leave a Comment

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