Home  >  Article  >  Database  >  MySQL 丢失密码问题

MySQL 丢失密码问题

WBOY
WBOYOriginal
2016-06-07 17:34:581126browse

重置MySQL密码:停止MySQL服务,使用skip-grant-tables参数启动

重置MySQL密码:

停止MySQL服务,使用skip-grant-tables参数启动   

service mysqld stop;
mysqld_safe --skip-grant-tables --user=mysql&

  此时无需授权就可以进入到MySQL命令行   
mysql>UPDATE mysql.user SET Password=PASSWORD('...') WHERE User='...' AND Host= '...';FLUSH PRIVILEGES;

  以上的操作还是会有一些纰漏:
  重置密码这个时间段内,任何人都能连接MySQL(除非数据库服务器屏蔽了外网访问);
  推荐方式:   
shell>service mysqld stop;
//将UPDATE mysql.user SET Password=PASSWORD('...') WHERE User='...' AND Host= '...';FLUSH PRIVILEGES;这句SQL语句写入到mysql有权限读取的目录;
mysql>mysqld_safe --init-file=/path/to/init/file --user=mysql &
//最后删除该文件,免得密码泄露;

  避免重启两次MySQL!!!
  值得一提的是:在MySQL5.6中,,使用mysql_config_editor加密.mylogin.cnf 进行登录;只要该文件存在,就不用考虑丢失密码的问题啦!

linux

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