mysql5.7 以上版本root密码重置

mysql5.7以上root用户密码重置

仅限centos系统 不要想Windows系统 Windows系统看了很多,几乎都是失败的,所以Windows系统是否可以修改都是问题。
这篇文章是开发中遇到了root用户密码设置错误,或者多次设置导致忘记密码,需要对root密码进行重新设置:

在51博客上看到的博主安静的疯子

[https://blog.51cto.com/quietmadman/1768057]
1,停止 mysql 服务

[root@study usr]# systemctl stop mysqld

2,设置 mysqld 选项 --skip-grant-tables 参数 也有在/etc/my.sqld文件下直接设置这个文件的,但是我在测试过程中并没有生效

[root@study usr]# systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

3,重新启动 mysql

[root@study usr]# systemctl start mysqld

4,执行 mysql -u root 登录 mysql,并更改密码
单独拿出来修改密码的位置,千万别改错了,否则需要自己更新成原样

UPDATE mysql.user SET authentication_string = PASSWORD('设置你的密码'), password_expired = 'N'  WHERE User = 'root' AND Host = 'localhost';
[root@study usr]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.11 MySQL Community Server (GPL)
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> UPDATE mysql.user
    ->     SET authentication_string = PASSWORD('newrootpasswd'), password_expired = 'N'
    ->     WHERE User = 'root' AND Host = 'localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

5,重置完密码后,去掉 --skip-grant-tables 参数后,重启 mysql
如果忘记去掉的话你的mysql依旧是没有密码直接登录的

[root@study usr]# systemctl unset-environment MYSQLD_OPTS
[root@study usr]# systemctl restart mysqld

再次登录,这时候需要再次输入密码,也就是你上面设置的密码

[root@study usr]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.11 MySQL Community Server (GPL)
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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值