mysql 忘记密码-重设密码

原文地址http://hi.baidu.com/hiliuqingwen/blog/item/167d61c5e3b8c7a18326ac08.html


解决mysql密码错误

# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user (using password: NO)


现在终于被我找到了解决方法,


方法一:
# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit

# /etc/init.d/mysql restart
# mysql -uroot -p
Enter password: <输入新设的密码newpassword>

mysql>


方法二:
直接使用/etc/mysql/debian.cnf文件中[client]节提供的用户名和密码:
# mysql -udebian-sys-maint -p
Enter password: <输入[client]节的密码>
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit

# mysql -uroot -p
Enter password: <输入新设的密码newpassword>

你可能感兴趣的:(mysql 忘记密码-重设密码)