阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

MySQL5.7.24 忘记root密码重设方法

139次阅读
没有评论

共计 1818 个字符,预计需要花费 5 分钟才能阅读完成。

在 Linux 下安装了 MySQL5.7.24,重新设置密码的时候竟然忘记 root 密码了,没办法,只能重新搞一下,亲测可用。

此处我用的是 MySQL5.7.24 的方法,其他版本的 MySQL 用这个方法或许不一样。

首先结束当前正在运行的 mysql 进程

linuxidc@linuxidc:~$ sudo /etc/init.d/mysql stop
[ok] Stopping mysql (via systemctl): mysql.service.

用 mysql 安全模式运行并跳过权限验证

linuxidc@linuxidc:~$ sudo mysqld_safe –user=mysql –skip-grant-tables –skip-networking &
[1] 22024
linuxidc@linuxidc:~$ 2018-11-01T08:39:38.987953Z mysqld_safe Logging to syslog.
2018-11-01T08:39:38.992011Z mysqld_safe Logging to ‘/var/log/mysql/error.log’.
2018-11-01T08:39:39.012604Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

用空密码方式使用 root 用户登录 MySQL

linuxidc@linuxidc:~$ sudo  mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24-0Ubuntu0.18.04.1 (Ubuntu)

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

MySQL5.7.24 忘记 root 密码重设方法

更新密码

mysql> update user set Password = PASSWORD(‘root’) where User =’root’;
ERROR 1054 (42S22): Unknown column ‘Password’ in ‘field list’

MySQL5.7.24 忘记 root 密码重设方法

执行后报错 ERROR 1054(42S22) Unknown column ‘password’ in‘field list’

错误的原因是 MySQL 5.7 版本下的 mysql 数据库下已经没有 password 这个字段了,password 字段改成了 authentication_string

所以请使用一下命令:

mysql> use mysql;
Database changed

mysql> select User from user;     #此处为查询用户命令
+——————+
| User            |
+——————+
| debian-sys-maint |
| mysql.session    |
| mysql.sys        |
| root            |
+——————+
4 rows in set (0.00 sec)

MySQL5.7.24 忘记 root 密码重设方法

mysql> update mysql.user set authentication_string=password(‘root’) where user=’root’;   #修改密码成功
Query OK, 1 row affected, 1 warning (0.11 sec)
Rows matched: 1  Changed: 1  Warnings: 1

MySQL5.7.24 忘记 root 密码重设方法

mysql> flush privileges;     #刷新权限立即生效
Query OK, 0 rows affected (0.05 sec)

退出

mysql> quit
Bye

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计1818字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中