mysql修改密码

 1. mysql最开始使用是没有密码的,要求输入密码时直接回车就可以,但是自己设置密码后就要输入密码才能登陆。下面就写一下在知道旧密码的情况下改密码。

进入mysql系统:set password for root@localhost = password('newpassword');将root的密码设置成newpassword

2.还有一种情况就是忘记原密码

    首先要停止mysql服务:service mysqld stop;

    跳过授权启动:mysql_safe --skip-grant-tables &

    以root用户登录:mysql -u root

    update mysql库的user表:use mysql;→update user set password=password('newpassword') where user = 'root' and host = 'localhost';→flush privileges;→quit

     然后重启mysql服务:service mysqld restart

原文地址:https://www.cnblogs.com/menggnem/p/5733391.html