解决linux下mysql初始密码或者密码忘记


1.   vim /etc/my.cnf

在[mysqld]下加入 

skip-grant-tables

(这个意思是跳过权限验证,可免密码登录 )

然后保存退出,

重启mysql 

2 ./etc/init.d/mysqld restart

登录

3  mysql -u root -p

4.  5.7版本前的mysql运行: update user set password=password("你的密码") where user="用户"; 

    5.7版本后的mysql运行:update mysql.user set authentication_string=password('你的密码') where user='用户';  

5 exit; #退出 

6 编辑my.cnf文件删掉或者注释skip-grant-tables 这一行,然后重启MySQL,/etc/init.d/mysqld restart,否则MySQL仍能免密码登录

7 mysql -u root -p输入密码

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM