Mysql 重置密码

2009年10月20日 | 分类: IT技术 | 标签:
< ?
echo "Welcome to AppServ MySQL Root Password Reset Program\n\n";
 
AppServCMD();
 
function AppServCMD() {
	define('STDIN',fopen("php://stdin","r"));
	echo " Enter New Password : ";
	$input = trim(fgets(STDIN,256));
	$input = ereg_replace('\"', "\\\"", $input);
	$input = ereg_replace('\'', "\'", $input); 
	echo "\n   Please wait ...................................\n\n";
	exec ("net stop mysql");
	exec ('start /b e:\AppServ\MySQL\bin\mysqld-nt.exe --skip-grant-tables --user=root');
	exec ("e:\AppServ\MySQL\bin\mysql -e \"update mysql.user set PASSWORD=PASSWORD('$input') 
                  where user = 'root';\"");
	exec ("e:\AppServ\MySQL\bin\mysqladmin -u root shutdown");
	sleep(3);
	exec ("net start mysql");
} // end function
 
?>

来自AppServ的一个小工具,可以重置Mysql账户密码,记录下以供查阅。
使用时需要PHP环境支持,并相应更改上面php文件中的mysql路径。

  1. 2009年11月17日12:24

    D:\>mysqladmin -uroot -p password abcd
    Enter password: ****