mysql 重置 root 密码

写这个东西的原因是我设置用户权限的时候将 root的localhost给干掉了, 结果连不上数据库了, 于是重置mysql的密码

1. 关闭当前的mysql服务

net stop mysql

2. 使用管理员跳过权限的方法开启mysql服务

mysql5.1 : mysqld --skip-grant-tables;
winserver: mysqld-nt --skip-grant-tables;
linux : mysqld_safe --skip-grant-tables

3. 使用命令进入mysql控制台(更新密码)

> mysql -uroot
> use mysql;
> update user set password=password('some password') where user='root';
> flush privileges;
> exit;

4. 添加用户
> grant all privileges on *.* to 'yourname'@'%' identified by 'youpasswd'
> flush privileges
>exit

5. 重启mysql服务器
> net stop mysql
> net start mysql;

重试登陆OK

你可能感兴趣的:(mysql,密码重置)