本来是风和日丽、阳光明媚的一天,然后开心的打开测试机捣鼓zabbix,突然一个mysql密码错误扰乱了我的心绪。哎,好烦,要去修改mysql密码了。
首先进入数据库登录时密码忘记,一直报错:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
怎么办啊,试了好久,没搞出来。
那么就去修改mysql的配置文件吧,切换root用户,编辑/etc/my.cnf文件。
在配置文件里面添加skip-grant-tables
重启数据库,使用无密码登录。
[[email protected]]# mysql -uroot
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is 1174
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MariaDB [(none)]>
在mysql的命令行输入:
update mysql.user set password=PASSWORD('新密码')where User='root';
然后在mysql的命令行输入:
flush privileges;
刷新一下权限,并使用quit退出数据库。
最后把/etc/my.cnf文件中的skip-grant-tables删除掉,重启数据库,使用新密码登录。
[[email protected] ]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is 1174
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MariaDB [(none)]>
mysql的密码修改成功了!
唯一的缺点就是需要重启mysql数据库,所以大家还是一定要记住mysql的密码!