MySQL root şifresinin sıfırlanması

MySQL root şifresi, root kullanıcısının MySQL veritabanına tam erişimini sağlar. Mysql veritabanında root şifresi hatırlanmadığında ya da bilinmediği durumlarda aşağıdaki gibi sıfırlanabilir. Sıfırlama için Linux ortamlarda root ile , windows ortamlarda administrator ile bağlantı sağlanması gerekmektedir.

Sıfırlama adımları aşağıdaki gibidir.

Mysql servisinin kapatılması :

Ubuntu ve Debian ise ;

/etc/init.d/mysql stop

CentOS, Fedora, Red Hat Enterprise Linux ya da  Oracle  Enterprise Linux ise ;

Mysql servisinin şifresiz başlatılması :

mysql -uroot

Yeni şifre verilmesi :

mysql cli üzerinden,

use mysql;

update user set password=PASSWORD(“yenisifre”) where User=’root’;

flush privileges;

quit

Mysql servisinin yeniden başlatılması :

Yeni şifre ile Mysql veritabanına bağlanılması :

ifre sorduğunda değiştirilen şifre girilip , mysql komut satırına bağlantı sağlanabilir.

Örnek çıktılar aşağıdaki gibi olacaktır.

root@debian:~# /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
root@debian:~# mysqld_safe –skip-grant-tables &
[1] 30091
root@debian:~# 180922 22:50:31 mysqld_safe Can’t log to error log and syslog at the same time.  Remove all –log-error configuration options for –syslog to take effect.
180922 22:50:31 mysqld_safe Logging to ‘/var/log/mysql/error.log’.
180922 22:50:31 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
root@debian:~# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.550+deb8u1 (Debian)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
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> 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> update user set password=PASSWORD(“yenisifre”) where User=‘root’;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 4  Changed: 0  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
root@debian:~# /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
root@debian:~#  /etc/init.d/mysql start
[ ok ] Starting mysql (via systemctl): mysql.service.
root@debian:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.550+deb8u1 (Debian)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
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>