Reset password user ‘root’ di MySQL Server maupun MariaDB Server
Lupa adalah hal yg wajar sebagai manusia, lupa bisa menjadi berkah dan sebaliknya bisa jadi bencana lho, apalagi yg menyandang status sysadmin… hehehe. đŸ˜€
Ok, hari ini saya akan menuliskan catatan dan berbagi pengalaman. Cara mereset password root database MySQL maupun MariaDB.
Langsung saja:
1. Langkah pertama, stop service daemon ‘mysqld’ untuk MySQL server dan ‘mysql’ untuk MariaDB.
[root@server ~]# service mysqld stop Stopping mysqld: [ OK ]
2. Jalankan lagi service mysql daemon secara ‘safe mode’, kemudian tkan tombol ctrl+c untuk kembali ke shell (dengan menekan tombol ctrl+c, secara harfiah kita telah menggagalkan suatu proses, tapi dalam kasus ini, service mysql masih berjalan kok).
[root@server ~]# mysqld_safe --skip-grant-tables --skip-networking & [1] 12731 [root@server ~]# 130204 20:00:06 mysqld_safe Logging to '/var/log/mysqld.log'. 130204 20:00:06 mysqld_safe A mysqld process already exists ^C [1]+ Exit 1 # note: dengan opsi --skip-grant-tables, berarti telah memperbolehkan login ke shell sql tanpa pengecekan password. Dan ini tidak aman, sehingga kita perlu menambahkan opsi --skip-networking, untuk mencegah query dari jaringan.
3. Dan kitapun berhasil masuk ke shell MySQL/ MariaDB tanpa password :).
[root@server ~]# mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.1.67 Source distribution Copyright (c) 2000, 2012, 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 3 rows in set (0.00 sec) mysql>
4. Setelah berhasil masuk ke shell MySQL/ MariaDB, kita bisa melakukan update password ke user yg kita inginkan, terutama user ‘root’.
mysql> update mysql.user set password = password('satudua3') where user='root'; Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed: 3 Warnings: 0 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,password,host from user; +------+-------------------------------------------+-----------+ | user | password | host | +------+-------------------------------------------+-----------+ | root | *200CFA46F92231BE79458247DEA35133DFFA3608 | localhost | | root | *200CFA46F92231BE79458247DEA35133DFFA3608 | server | | root | *200CFA46F92231BE79458247DEA35133DFFA3608 | 127.0.0.1 | +------+-------------------------------------------+-----------+ 5 rows in set (0.00 sec) mysql> \q Bye
5. Selanjutnya, lakukan restart kepada service ‘mysqld’ untuk MySQL server atau ‘mysql’ untuk MariaDB server daemon.
[root@server ~]# service mysqld restart Stopping mysqld: [ OK ] Starting mysqld: [ OK ]
6. Pastikan mysql daemon sudah bekerja dengan benar.
[root@server ~]# mysql -u root ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) ## Akses dilarang karena tidak menyertakan password [root@server ~]# mysql -u root -p Enter password: ******* ## password mysql, dan kita pun bisa login. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.1.67 Source distribution Copyright (c) 2000, 2012, 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>
S.E.K.I.A.N
sumber: disini