最近也不知道是懒了仍是老了,几天没碰数据库居然把密码忘了,这就比如吃饭的家伙锁在箱子里,那还怎么吃饭?因此我得把mysql密码相关的都整理一下,省得还得招人开锁,那实在是太尴尬了。mysql
实验目的:忘记用户密码,修改用户密码sql
在安装mysql的时候有一个跳过密码的步骤,先试一试行不行数据库
vim /etc/my.cnf
在[mysqld]下面加上一句vim
skip-grant-tables
重启mysql服务ide
systemctl restart mysqld.service
经过无密码方式登陆mysql服务this
mysql –uroot –p
不加-p也行,加了-p会出现让你输入密码的步骤,直接回车就进去了。不加-p则直接进入mysqlspa
如今修改密码,出现了错误rest
alter user root@localhost identified by '123456';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statementcode
刷新一下server
flush privileges;
再试一次,主要缘由是skip-grant-tables使得数据库只能是只读的权限
好了
如今退出数据库,并删除刚才添加的skip-grant-tables
重启mysql
systemctl restart mysqld.service
如今就能够经过密码登陆了