Reset Password MySQL di Linux

Kebetulan saya lagi di Kali Linux. Untuk setup MySQL masih perlu untuk konfigurasi passwordnya. Karena secara default kita tidak bisa masuk sebagai root karena passwordnya belum diketahui.

Jadi di artikel ini akan mereset password untuk akun user root.

Install MySQL server menggunakan APT:

$ sudo apt install mysql-common

Lalu masuk ke MySQL menggunakan privilege sudo:

$ sudo mysql

Setelah itu menu MySQL di terminal akan terbuka:

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 10.6.7-MariaDB-3 Debian buildd-unstable

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

Masukkan perintah:

`ALTER USER 'root'@'localhost' IDENTIFIED BY 'password_yang_diinginkan';`

Fungsi diatas akan merubah password untuk username root. Dan sesuaikan dengan password yang dimau.

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 10.6.7-MariaDB-3 Debian buildd-unstable

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> `ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';`

Karena saya pengen passwordnya sama seperti nama user maka saya masukin root sebagai passwordnya. Jadi nanti kalau mau login ke MySQL dan masukkan username root dan passwordnya juga root.

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 10.6.7-MariaDB-3 Debian buildd-unstable

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.075 sec)

MariaDB [(none)]> 

Oke sudah selesai, exit terminal MySQLnya dan login dengan akun root:

$ mysql -uroot -proot

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 10.6.7-MariaDB-3 Debian buildd-unstable

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>