mysql安装在centos7报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

【问题】:
mysql版本:5.7.13

首次在centos下安装mysql,客户端连接mysql时报错:


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

【解决】:
1、找到密码


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

2、重新连接mysql:


     
     
     
     
  1. [root@zzs171 opt] # /usr/bin/mysql -u root -p
  2. Enter password:
输入上面找到的密码,即可进入mysql客户端连接。

3、修改mysql的root的密码:
进入mysql客户端之后,show databases; 会提醒先修改密码:


     
     
     
     
  1. mysql> show databases;
  2. ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
设置密码,以下两种方式均可:


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


OK,至此设置成功。注意mysql有密码复杂度的限制。密码太简单会提示:

     
     
     
     
  1. mysql> SET PASSWORD FOR 'root'@ 'localhost' = PASSWORD( '123');
  2. ERROR 1819 (HY000): Your password does not satisfy the current policy requirements


【其他补充】
网上还有几种方案,但是都不行。例如:


     
     
     
     
  1. 方案一:
  2. mysqladmin -u root password 123456,结果提示错误:error: 'Access denied for user 'root'@'localhost' (using password: NO)'
  3. 方案二:
  4. 用mysqld_safe skip- grant- tables进入mysql,然后 sql语句修改root密码,还是提示错误:-bash: mysqld_safe: command not found


            

你可能感兴趣的:(mysql安装在centos7报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO))