mysql安裝在centos7報錯ERROR 1045 (28000): Access denied for user 'root'@'localhost' (u...

轉:https://blog.csdn.net/kuluzs/article/details/51924086

 
mysql版本:5.7.13

首次在centos下安裝mysql,客戶端鏈接mysql時報錯:html

 

[root@localhost opt]# /usr/bin/mysql -u root ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

【解決】:
一、找到密碼

 

[root@localhost opt]# cat /var/log/mysqld.log | grep password 2016-07-16T05:01:47.771362Z 1 [Note] A temporary password is generated for root@localhost: q.)aq!YaH6y- 2016-07-16T05:02:32.000199Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO) 2016-07-16T05:02:39.063852Z 3 [Note] Access denied for user 'root'@'localhost' (using password: NO)

二、從新鏈接mysql:

 

[root@zzs171 opt]# /usr/bin/mysql -u root -p Enter password: 
輸入上面找到的密碼,便可進入mysql客戶端鏈接。

三、修改mysql的root的密碼:
進入mysql客戶端以後,show databases; 會提醒先修改密碼:mysql

 

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
設置密碼,如下兩種方式都可:

 

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('Mysqlpassw0rd.'); alter user 'root'@'localhost' identified by 'Mysqlpassw0rd.';

 

OK,至此設置成功。注意mysql有密碼複雜度的限制。密碼太簡單會提示:
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123'); ERROR 1819 (HY000): Your password does not satisfy the current policy requirements


【其餘補充】
網上還有幾種方案,可是都不行。例如:

 

方案一:
mysqladmin -u root password 123456,結果提示錯誤:error: 'Access denied for user 'root'@'localhost' (using password: NO)'

方案二:
用mysqld_safe skip-grant-tables進入mysql,而後sql語句修改root密碼,仍是提示錯誤:-bash: mysqld_safe: comm
相關文章
相關標籤/搜索