Home >Database >Mysql Tutorial >mysql忘记密码问题解决方案_MySQL

mysql忘记密码问题解决方案_MySQL

WBOY
WBOYOriginal
2016-06-01 13:10:29930browse

一:直接查看密码
  目录如下:cat /root/.mysql_secret 

二:修改my.cnf文件如下,可跳过密码验证
 
  [mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock


skip-grant-tables     这里新加的代码


user=root


[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid 

然后保存,重启mysql

运行mysql即可直接进入数据库
mysql> USE mysql ; 
mysql> UPDATE user SET Password = password ( 'new-password' ) WHERE User = 'root' ;     
这里的“=”号后面的password是方法名,就是mysql自带的密码加密规则,不允许变动。
mysql> flush privileges ;   
mysql> quit;

然后修改my.cnf,将 skip-grant-tables这段删除,重启mysql即可按设置的密码登录了。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn