Linux 系统下MySQL忘记root密码解决办法

来源:互联网 发布:java 数据类型 double 编辑:程序博客网 时间:2024/05/16 11:53

1。在/etc/目录下找到my.conf (如果你用rpm安装mysql,默认是没有my.conf的。你可以到你的安装目录一般位于/usr/share/mysql下找到my-default.conf,拷贝一份到/etc/目录下)

执行命令 vi my.conf

添加 skip-grant-mysql ,保存退出

2. 执行命令 systemctl restart mysql (重启mysql服务,我用的是Centos7.0的版本。不同版本命令可能有所不同,低版本的Centos可以用 service mysql restart)

3 直接执行命令 mysql 就可以进入了

4 进入后执行命令

UPDATE user SET Password=PASSWORD('newpassword') where USER='root';

FLUSH PRIVILEGES;

5 退出后把你刚才的skip-grant-mysql删掉就行了

6 你就可以用root用户进去了,进去后执行命令是,可能会提示你设置密码,你执行 set Password=password('newpassword');就可以了


0 0
原创粉丝点击