windows下mysql密码忘了怎么办?【转】

前两天在windows的command命令行下,用mysqladmin导入过一些站上数据

结果悲催了,mysql.user的内容被改了,root上不了了,权限也变了。

结合了网络上的集中方法,终于成了。

步骤如下:

一、先把mysql停了,

win:net stop mysql

linux:service mysqld stop

以下以windows 为例

二、用mysqld hold住mysql

#mysqld --skip-grant-tables 执行后cmd窗口会Hold住,别关闭,新开一个cmd窗口

三、进入mysql

在新开的cmd窗口里,输入

#mysql -hlocalhost -uroot

没有输入密码就进入了哦,亲

四、两种操作:

A、更改密码:

UPDATE user SET Password=PASSWORD('xxx') WHERE user='root';

B、如果更改密码了还不行,那估计和我一样,权限都被导入的库冲掉了。

还需要授权,以下sql适用于mysql5.5

update user set Select_priv = "Y",Insert_priv = "Y",Update_priv = "Y",Delete_priv = "Y",Create_priv = "Y",Drop_priv = "Y",Reload_priv = "Y",Shutdown_priv = "Y",Process_priv = "Y",File_priv = "Y",Grant_priv = "Y",References_priv = "Y",Index_priv = "Y",Alter_priv = "Y",Show_db_priv = "Y",Super_priv = "Y",Create_tmp_table_priv = "Y",Lock_tables_priv = "Y",Execute_priv = "Y",Repl_slave_priv = "Y",Repl_client_priv = "Y",Create_view_priv = "Y",Show_view_priv = "Y",Create_routine_priv = "Y",Alter_routine_priv = "Y",Create_user_priv = "Y" where user="root";

五、最后别忘了刷新权限

flush privileges;

OK了,关闭一切命令行,启动mysql服务,用mysql管理工具登录看看吧。

上一篇:百度地图、ECharts整合HT for Web网络拓扑图应用


下一篇:MySQL找出锁等待