描述
使用到是阿里雲服務器,系統為cent Os,給某個賬戶授權之后,root的賬戶就登錄不進去了,原本root賬戶設置好了遠程連接的權限了,網上搜索了一大堆,終於自己摸索得到了幾個方法
產生原因
- root賬戶不能遠程連接
- mysql中存在空賬戶
- root賬戶密碼錯誤(可能是密碼輸錯,因為linux輸入密碼什么都不顯示..)
解決方法
以下的三種方法,其實都是要進入mysql的安全模式中,對默認的user表進行修改
設置root賬戶為遠程
#1.停止mysql數據庫
service mysql stop
#2.執行如下命令
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
#3.使用root登錄mysql數據庫
mysql -u root mysql
4.修改root賬戶可以遠程連接
mysql> update user set host='%' where user='root' and host='localhost';
# mysql5.7MySQL請采用如下SQL:
mysql> UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';
#5.刷新權限(必須,防止mysql的緩存影響)
mysql> FLUSH PRIVILEGES;
#6.退出mysql
mysql> quit
#7.重啟mysql
service mysql restart
#8.使用root用戶重新登錄mysql
mysql -uroot -p
Enter password: <輸入新設的密碼newpassword>
刪除空賬戶
#1.停止mysql數據庫
service mysql stop
#2.執行如下命令
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
#3.使用root登錄mysql數據庫
mysql -u root mysql
4.刪除空用戶
mysql> mysql> delete from user where user='';
# mysql5.7MySQL請采用如下SQL:
mysql> UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';
#5.刷新權限(必須,防止mysql的緩存影響)
mysql> FLUSH PRIVILEGES;
#6.退出mysql
mysql> quit
#7.重啟mysql
service mysql restart
#8.使用root用戶重新登錄mysql
mysql -uroot -p
Enter password: <輸入新設的密碼newpassword>
修改密碼
#1.停止mysql數據庫
service mysql stop
#2.執行如下命令
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
#3.使用root登錄mysql數據庫
mysql -u root mysql
4.修改密碼
mysql> update user ser password = password('newpassword') where user = 'root';
# mysql5.7以上,請采用如下SQL:
mysql> UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';
#5.刷新權限(必須,防止mysql的緩存影響)
mysql> FLUSH PRIVILEGES;
#6.退出mysql
mysql> quit
#7.重啟mysql
service mysql restart
#8.使用root用戶重新登錄mysql
mysql -uroot -p
Enter password: <輸入新設的密碼newpassword>
參考鏈接:
百度知道 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
解決 ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'
PS:歡迎評論,提出錯誤,補充解決方法