linux安裝mysql後root無法登錄

問題:

[root@localhost mysql]# mysql -u root -p 
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (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> 


方法二(如何存在的情況下,ubuntu存在,centos不存在): 
直接使用/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>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章