Linux+mysql重置_linux环境mysql重置密码

mysql重置密码

Linux环境下,忘记mysql密码怎么办?这里提供两种解决方案。

第一种方案:

在my.cnf配置文件中添加“跳过登陆密码验证”配置项

sed -i "/\[mysqld\]/ a\skip-grant-tables" /etc/my.cnf

重启mysqld守护进程,重新加载配置

service mysqld restart

直接无账户无密码登陆mysql

[root@pingkou-developer2 etc]# mysql

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.5.51-log MySQL Community Server (GPL) by Remi

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type "help;" or "\h" for help. Type "\c" to clear the current input statement.

重新设置root账户密码后,退出登录

mysql> update `mysql`.`user` set `password`=password("admin") where `user`="root";

Query OK, 0 rows affected (0.00 sec)

Rows matched: 3 Changed: 0 Warnings: 0

mysql> exit;

Bye

在my.cnf配置文件中,将skip-grant-tables配置项注释掉,加#注释

sed -i "s/skip-grant-tables/#&/" /etc/my.cnf

重启mysqld守护进程,重新加载配置

[root@pingkou-developer2 pingkou]# service mysqld restart

Stopping mysqld: [ OK ]

Starting mysqld: [ OK ]

使用新密码重新登陆mysql,结束

[root@pingkou-developer2 pingkou]# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.5.51-log MySQL Community Server (GPL) by Remi

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type "help;" or "\h" for help. Type "\c" to clear the current input statement.

mysql>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值