liuhongyu 发表于 2018-10-7 10:12:58

解决mysql忘记密码

  经常在登录mysql时会报以下错误:
  # mysql -uroot -p1
  ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
  解决方法:
  ①首先进入安全模式,添加如下
  # vim /etc/my.cnf
  
  ......
  skip-grant-tables
  ②然后重启mysql
  # systemctl restart mariadb
  ③直接登录mysql,使用update方式修改root密码
  # mysql
  MariaDB [(none)]> update mysql.user set password= password('0') where user='root' and host='localhost';
  Query OK, 1 row affected (0.00 sec)
  Rows matched: 1Changed: 1Warnings: 0
  MariaDB [(none)]> flush privileges;
  Query OK, 0 rows affected (0.02 sec)
  MariaDB [(none)]> exit
  Bye
  ④退出安全模式,将/etc/my.cnf添加的skip-grant-tables命令去掉
  然后重启即可用刚刚的密码登录
  # systemctl restart mariadb
  # mysql -uroot -p0

页: [1]
查看完整版本: 解决mysql忘记密码