PDA

View Full Version : Reset password MySQL trên Linux và Windows


latigo7441
30-05-2012, 02:17 PM
I. Trên Windows:
Vào Start -> Run -> gõ
services.msc
Enter
Tìm services MySQL (http://www.cpanel.vn/tag/mysql-2) và stop lại
Sau đó bạn vào Command, tìm đến thư mục bin của MySQL:
Vào Start -> Run -> gõ: cmd —> EnterVí dụ bạn để mysql ở C:\MySQL. Gõ lệnh sau:
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
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
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.
II. 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:
[user@localhost ~]$ su -
Password:
[root@localhost user]#
2. First you have to stop the daemon – Dừng ngay mysql lại
[root@localhost root]# /etc/init.d/mysqld stop
[root@localhost root]#
3. Nếu sử dụng RedHat, CentOS… thì dùng
[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 – đề phò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.
[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:
[root@localhost root]# kill `cat /var/run/mysqld/mysqld.pid`
6. And finally restart it – và cuối cùng khởi động lại:
[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:
[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 :
[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

source
cpanel.vn