Home > Database > Mysql Tutorial > body text

Windows/Linux MySQL忘记root密码的解决方法

WBOY
Release: 2016-06-07 17:30:23
Original
981 people have browsed it

MySQL的root用户密码往往容易被遗忘,它本身就有一个跳过权限检查启动的机制用来处理权限错误问题。本文分别对Windows环境与Linu

MySQL的root用户密码往往容易被遗忘,它本身就有一个跳过权限检查启动的机制用来处理权限错误问题。本文分别对Windows环境与Linux环境下介绍MySQL忘记密码/重置密码的方法,希望帮助初学者解决丢失密码的烦恼。 

MySQL for Windows重置密码

一般来说,Windows下的MySQL是安装成服务运行的。本文将以Windows 2003为例。

1、首先在 控制面板 – 管理工具 – 服务 中将MySQL服务停止。

2、以安全模式(跳过权限认证)启动MySQL服务

“开始菜单” – “运行” – 输入“cmd”并回车 – cd至MySQL安装目录下的 bin 目录,然后执行:

 

1 mysqld-nt.exe --skip-grant-tables

3、此时MySQL已经正常运行,通过PhpMyAdmin登录MySQL,用户名root,密码为空或任何其他字符; 

MySQL for Linux重置密码

Linux下重置密码的原理与Windows下类似,,都是采用安全模式跳过权限检查启动MySQL。

1、首先停止MySQL服务,执行如下命令:

 

1 [root@www ~]# /etc/init.d/mysql stop

2、以安全模式启动MySQL:

1 [root@www ~]# /usr/local/mysql/bin/mysqld_safe --skip-grant-tables &

3、此时即可通过phpMyAdmin或者命令行修改密码。用户名为root,密码为空即可。 

附修改密码的命令:

首先以命令行模式登录MySQL:

1 [root@www ~]# mysql -u root -p

然后执行如下三条命令:

>use mysql;
> update user set password=password(“新密码”) where user=”root”;
> flush privileges;

linux

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!