linux下mysql忘记密码

10 篇文章 0 订阅
9 篇文章 0 订阅
mysql 5.7版本的数据库下没有password字段,password字段改成了 authentication_string


1.由于当前不知mysql密码,故需要设置跳过密码验证,修改my.cnf配置文件
vi /etc/mysql/my.cnf 添加skip-grant-tables


[mysqld]
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
explicit_defaults_for_timestamp
skip-grant-tables


2.重启MySQL, service mysql restart
# service mysql restart
* Stopping MySQL Community Server 5.7.9
...
* MySQL Community Server 5.7.9 is stopped
* Re-starting MySQL Community Server 5.7.9
..
* MySQL Community Server 5.7.9 is started


3.命令行进入mysql
选择mysql数据库use mysql




4.使用mysql语句更新root密码
update user set authentication_string=password('你的密码') where user='root';


若需要修改mysql密码
mysql> alter user 'root'@'localhost' identified by 'root';
这样也可以:set password for 'root'@'localhost'=password('root');
5.更新mysql密码后,将my.cnf文件恢复原状,即删除或注释skip-grant-tables
6.再次重启mysql。service mysql restart
7.测试root密码是否修改成功
不输入密码时,
root@home:# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)


输入密码时,
root@home:# mysql -uroot -proot
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.9 MySQL Community Server (GPL)


Copyright (c) 2000, 2015, 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>



参考:

http://blog.csdn.net/u010603691/article/details/50379282

http://www.jb51.net/article/77858.htm

http://blog.csdn.net/gggxwy/article/details/6621627

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值