更新密码
-- setSET PASSWORD FOR 'root'@'localhost' = PASSWORD('*****');-- upateUPDATE mysql.user SET password=PASSWORD('新密码') WHERE User='root';FLUSH PRIVILEGES;
mysqladmin 方式
格式:mysqladmin -u用户名 -p旧密码 password 新密码
# 给root加个密码ab12, 开始时root没有密码,所以-p旧密码一项就可以省略
mysqladmin -u root -password ab12。
# 将root的密码改为djg345。
mysqladmin -u root -p ab12 password djg345
Mysql 重置 root密码
写这个东西的原因是我设置用户权限的时候将 root的localhost给干掉了, 结果连不上数据库了, 于是重置mysql的密码
- 关闭当前的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 mysql > use mysql;
<= mysql5.6
mysql > update user set password=password(‘some password’) where user=’root’;
mysql 5.7+
mysql > update user set authentication_string=password(‘some password’) where user=’root’ mysql > flush privileges; mysql > exit;
4. 添加用户
mysql > grant all privileges on . to ‘yourname’@’%’ identified by ‘youpasswd’ mysql > flush privileges mysql > exit
5. 重启mysql服务器
net stop mysql net start mysql;
``` 重试登陆OK
