Access[root@log01 ~]# mysql -u root -pmysql
Enter password: sql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) denied for user 'root'@'localhost' (using password: NO)測試
我猜測是否是密碼忘記了。。。而後準備修改密碼:ui
#mysqladmin -u root -p password 123456 ###設置root密碼爲123456rest
Enter password: server
mysqladmin: connect to server at 'localhost' failedip
error: 'Access denied for user 'root'@'localhost' (using password: YES)'it
依然報這個錯誤。。。蛋疼了,百度一下,最終找到了方法以下:table
方法一: cli
# /etc/init.d/mysqld 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/mysqld 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>
方法三:
這種方法我沒有進行過測試,由於個人root用戶默認密碼已經被我修改過了,那位有空測試一下,把結果告訴我,謝謝!
# mysql -uroot -p
Enter password: <輸入/etc/mysql/debian.cnf文件中[client]節提供的密碼>