[转载]mysql root密码忘了怎么办

   如果忘记了root密码是可以修改的,之前遇到这种情况,下面将解决方法记录下来。

      首先在mysql的目下找到mysqld.exe文件,然后再cmd窗口下运行

      如:mysqld.exe –skip-grant-table

此时不要关闭该窗口,然后再打开一个cmd窗口,进行如下修改

    >Mysql –uroot

    > updatemysql.user set password=password(‘pass’) where user=’root’;

    > flushprivileges;

    如果在linux系统下,则可以先将mysql服务停下来,使用命令 service mysql stop,若该命令不行,则需要root权限

    #/etc/rc.d/init.d/mysqlstop

   #mysql_safe –skip-grant-tables&

   # updateuser set password=password(‘pass’) where user=’root’;

   #flushprivileges;

   另外如果要授权给root对所有数据库的操作权限,密码为test,则可以使用如下命令:

     Grant all on*.* to ‘root’@’%’ identified by “test”;

原文地址:https://www.cnblogs.com/kingcucumber/p/2837846.html