MySQL root şifresini sıfırlamak için öncelikle MySQL servisini durduralım.

sudo systemctl stop mysql.service

Servisi kontrol edelim.

sudo systemctl status mysql.service
● mariadb.service - MariaDB 10.3.34 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Sun 2022-04-17 12:24:38 UTC; 2s ago
       Docs: man:mysqld(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 20540 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION (code=exited, status=0/SUCCESS)
   Main PID: 20540 (code=exited, status=0/SUCCESS)
     Status: "MariaDB server is down"

MySQL başlarken tablo ve network kontrolünü devre dışı bırakıyoruz.

sudo systemctl set-environment MYSQLD_OPTS="--skip-networking --skip-grant-tables"

MySQL servisini tekrardan başlatıyoruz.

sudo systemctl start mysql.service

Servisi kontrol ediyoruz.

sudo systemctl status mysql.service
● mariadb.service - MariaDB 10.3.34 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-04-17 12:27:31 UTC; 2s ago
       Docs: man:mysqld(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 21825 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
    Process: 21834 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 21837 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, status=0/SUCCESS)
    Process: 21915 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 21917 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
   Main PID: 21884 (mysqld)
     Status: "Taking your SQL requests now..."
      Tasks: 31 (limit: 9441)
     Memory: 83.3M
     CGroup: /system.slice/mariadb.service
             └─21884 /usr/sbin/mysqld --skip-networking --skip-grant-tables

Root olarak MySQL’a bağlanıyoruz.

sudo mysql -u root

Önceki izinleri temizleyelim.

flush privileges;
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)

MySQL DB’sine geçiş yapalım.

USE mysql

Aşağıdaki komutta ‘yeni-sifre’ kısmını tırnakları silmeden içerisindeki yazıyı şifreniz ile değiştirin.

ALTER USER  'root'@'localhost' IDENTIFIED BY 'yeni-sifre';

MySQL’dan çıkış yapalım.

quit;
MariaDB [mysql]> quit;
Bye

Tüm proccessleri kill edelim.

sudo killall -u mysql

MySQL servisini restart edelim.

sudo systemctl restart mysql.service

Yeni şifremizle giriş yapmayı deneyelim.

sudo mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 36
Server version: 10.3.34-MariaDB-0ubuntu0.20.04.1 Ubuntu 20.04

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)]> 

Cheers!