zhjx0521

方法一: 

在mysql系统外,使用mysqladmin

1 mysqladmin -u root -p password "test123"
2 Enter password: 【输入原来的密码】

方法二: 
通过登录mysql系统

1 mysql -uroot -p
2 Enter password: 【输入原来的密码】
3 mysql>use mysql;
4 mysql> update user set password=passworD("test") where user=\'root\';
5 mysql> exit; 

注意:如果Mysql的版本是5.7及以上的话update语句更换如下:

1 mysql> update user set authentication_string=passworD("test") where user=\'root\';

 

首先拿到操作系统的root权限,然后kill掉Mysql服务或者手动stop掉,这里我推荐使用手动stop;

1 service mysql stop

然后执行

1 mysqld_safe --skip-grant-tables &

&,表示在后台运行,不再后台运行的话,就再打开一个终端吧。

接着登陆MySQL修改密码

1 mysql
2 mysql> use mysql;
3 mysql> UPDATE user SET password=password("test123") WHERE user=\'root\';   
4 mysql> exit; 

注意:如果Mysql的版本是5.7及以上的话update语句如下:

1 mysql> update user set authentication_string=passworD("test") where user=\'root\';

修改后重启服务生效。

 

分类:

技术点:

相关文章:

  • 2021-06-17
  • 2021-12-30
  • 2021-12-09
  • 2021-11-21
  • 2021-11-21
  • 2021-12-20
  • 2021-11-20
猜你喜欢
  • 2021-12-14
  • 2021-11-21
  • 2021-09-23
  • 2021-11-15
  • 2021-12-16
  • 2021-11-21
  • 2021-11-21
相关资源
相似解决方案