忘记root用户密码,提示"ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)"
1.重置root用户密码,找到my.cf,命令locate my.cnf
2.在my.cnf中添加配置保存,命令vi my.cnf
[mysqld]
skip-grant-tables #跳过权限列表
3.重启数据库,命令 systemctl restart mariadb
4.再次登录不需要密码,命令mysql -uroot
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.1.17-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
5.修改root用户密码,命令use mysql;切换到mysql数据库,执行SQL,
update user set password=password("123456") where user="root";(5版本)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root' PASSWORD EXPIRE NEVER;(8版本)
6.赋权限,GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
刷新权限,FLUSH PRIVILEGES;
7.去掉my.cnf文件中的skip-grant-tables,重启mariadb,命令命令 systemctl restart mariadb
8.验证密码是否修改成功,mysql -uroot -p123456