Trên Windows:
vào Start -> Run -> gơ
Enter
T́m services MySQL và stop lại
sau đó t́m thư mục cài đặt mySQL giả sử C:\mySQL
Vào Start-> Run -> gơ
Enter.
ta vào thư mục bin
và gơ lệnh
Code:
C:\mySQL\bin\>mysqld-nt --skip-grant-tables
Giữ nguyên cửa số đó và mở thêm 1 cửa sổ command mới
vào bin và gơ lệnh
Code:
C:\mySQL\bin\>mysql -u root
khi đó sẽ login vào root mà không cần password.
Để Reset password root ta dùng lệnh
Code:
mysql>use mysql; update user set Password=PASSWORD('new_pass') WHERE User='root';FLUSH PRIVILEGES;
trong đó new_pass chính là password của bạn.
Trên Linux:
Trường hợp cài đặt bằng gói RPM:
1. Gain root access to your Linux system - Lên quyền root:
Code:
[user@localhost ~]$ su -
Password:
[root@localhost user]#
2. First you have to stop the daemon - Dừng ngay mysql lại
Code:
[root@localhost root]# /etc/init.d/mysqld stop
[root@localhost root]#
3. Nếu sử dụng RedHat, CentOS... th́ dùng
Code:
[root@localhost root]# mysqld_safe --skip-grant-tables --skip-networking
[root@localhost root]#
Nếu dùng OS khác (ubutun...) th́ thay thế services mysqld_safe thành safe_mysqld
You will now start MySQL in safe mode without reading the grant tables with all MySQL database passwords and also you will disable networking. The "safe_mysqld" command will do this trick for you. Chạy mysql trong safe_mode mà không cần đăng nhập và bạn cũng sẽ disable networking cho mysql luôn - đề pḥng thằng nào nhân cơ hội này nó vào

).
4. The "mysqladmin" command will now reset[rewrite] the root password. In this case we are setting it to "newpassword". sử dụng mysqladmin sẽ reset lại password. Trong trường hợp này ta phải sử dụng lệnh sau để set 1 pass mới.
Code:
[root@localhost root]# mysqladmin -u root flush-privileges password "newpassword"
[root@localhost root]#
5. Stop the running daemon - Dừng chạy cái mysql_safe:
Code:
kill `cat /var/run/mysqld/mysqld.pid`
6. And finally restart it - và cuối cùng khởi động lại:
Code:
[root@localhost root]# /etc/init.d/mysqld start
[root@localhost root]#
7. You can use now your new root password - Bây giờ th́ xài pass mới xem:
Code:
[root@localhost root]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 4.0.20-standard
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
XOng.
Trường hợp cài = source:
T́m thư mục cài đặt
Mysql và t́m thư mục
libexec bên trong nó. Bạn chạy lệnh :
Code:
[root@localhosthost libexec]./mysqld stop
[root@localhosthost libexec]./mysqld --skip-grant-tables --user=root
sau đó có thể tiến hành đăng nhập không cần password và reset password như trên windows
Đổi password, set password trong mySQL command