Difference between revisions of "Reset Password MySQL"

From OnnoWiki
Jump to navigation Jump to search
 
Line 12: Line 12:
  
 
  /etc/init.d/mysql stop
 
  /etc/init.d/mysql stop
 +
 +
killall mysqld
 +
killall mysqld
  
 
Output:
 
Output:
Line 18: Line 21:
  
 
* Jalankan server MySQL tanpa password:
 
* Jalankan server MySQL tanpa password:
 
mysqld_safe –skip-grant-tables &
 
 
atau
 
  
 
  sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
 
  sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
 
Output:
 
 
121224 11:09:53 mysqld_safe Logging to syslog.
 
121224 11:09:53 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
 
121224 11:09:55 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
 
[1]+  Done                    mysqld_safe –skip-grant-tables
 
  
 
* Login ke server MySQL menggunakan client MySQL:
 
* Login ke server MySQL menggunakan client MySQL:
Line 45: Line 37:
 
* Tentukan password baru bagi pengguna root MySQL:
 
* Tentukan password baru bagi pengguna root MySQL:
  
  use mysql;
+
  USE mysql;
  UPDATE mysql.user SET Password=PASSWORD(‘new_password’) WHERE User=’root’;
+
  UPDATE user SET Password = PASSWORD('newpwd') WHERE Host = 'localhost' AND User = 'root';
 
  FLUSH PRIVILEGES;
 
  FLUSH PRIVILEGES;
 
  quit
 
  quit
Line 53: Line 45:
  
 
  use mysql;
 
  use mysql;
  UPDATE mysql.user SET Password=PASSWORD(‘123456’) WHERE User=’root’;
+
  UPDATE user SET Password = PASSWORD('123456') WHERE Host = 'localhost' AND User = 'root';
 
  FLUSH PRIVILEGES;
 
  FLUSH PRIVILEGES;
 
  quit
 
  quit
  
 
* Beberapa alternatif lain
 
 
SET PASSWORD FOR root@'localhost' = PASSWORD('password');
 
 
UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
 
 
USE mysql
 
UPDATE user SET Password = PASSWORD('newpwd')
 
WHERE Host = 'localhost' AND User = 'root';
 
 
USE mysql
 
UPDATE user SET Password = PASSWORD('newpwd')
 
WHERE Host = '%' AND User = 'root';
 
  
 
* Hentikan server MySQL:
 
* Hentikan server MySQL:

Latest revision as of 13:21, 29 July 2013

Kita dapat merecover password server database MySQL dengan 5 langkah berikut:

  1. Hentikan (stop) proses server MySQL.
  2. Jalankan (start) proses server atau daemon MySQL (mysqld) dengan opsi –skip-grant-tables sehingga tidak akan menampilkan prompt password.
  3. Masuk (login melalui tool mysql) ke server MySQL sebagai pengguna root.
  4. Tulis password baru bagi root.
  5. Keluar dan restart server MySQL.

Berikut ini adalah contoh penerapan kelima langkah di atas (pastikan anda login di Linux sebagai ‘root’, kalo di Windows jadilah Administrator tertinggi):

  • Hentikan layanan MySQL:
/etc/init.d/mysql stop
killall mysqld
killall mysqld

Output:

Stopping MySQL database server: mysqld.
  • Jalankan server MySQL tanpa password:
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
  • Login ke server MySQL menggunakan client MySQL:
mysql -u root mysql

Output:

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql>
  • Tentukan password baru bagi pengguna root MySQL:
USE mysql;
UPDATE user SET Password = PASSWORD('newpwd') WHERE Host = 'localhost' AND User = 'root';
FLUSH PRIVILEGES;
quit
  • atau kalau password root 123456
use mysql;
UPDATE user SET Password = PASSWORD('123456') WHERE Host = 'localhost' AND User = 'root';
FLUSH PRIVILEGES;
quit


  • Hentikan server MySQL:
/etc/init.d/mysql stop

Output:

Stopping MySQL database server: mysqld
STOPPING server from pid file /var/run/mysqld/mysqld.pid
mysqld_safe[6186]: ended
[1]+ Done mysqld_safe –skip-grant-tables

Jalankan server MySQL dan uji perubahan yang telah terjadi:

/etc/init.d/mysql start
mysql -u root -p

Cara Reconfigure MySQL di Debian / Ubuntu

Kalau di Debian dan anak cucunya malah lebih gampang lagi Pak, tinggal dgn satu perintah:

sudo dpkg-reconfigure mysql-server

selesai masalah

Referensi

Pranala Menarik