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

栏目: 数据库 · 发布时间: 7年前

内容简介:在Linux下安装了MySQL5.7.24,重新设置密码的时候竟然忘记root密码了,没办法,只能重新搞一下,亲测可用。此处我用的是MySQL5.7.24的方法,其他版本的MySQL用这个方法或许不一样。首先结束当前正在运行的mysql进程

Linux 下安装了 MySQL 5.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

Linux公社的RSS地址https://www.linuxidc.com/rssFeed.aspx

本文永久更新链接地址: https://www.linuxidc.com/Linux/2018-11/155125.htm


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

微信小程序

微信小程序

牛建兵 / 清华大学出版社 / 2017-9-1 / 49.00

微信小程序从满城风雨到掀起创业热潮,再到一直不断地迭代更新,其每一次更新都会增加新能力,让使用变得越来越方便,同时也增加一批进军小程序的队伍。微信小程序作为现在互联网中的热点,它给创业者、投资者、程序员带来了福音。对创业者来说,小程序能大大降低他们的创业成本,同时也降低了投资者的投资风险。 本书注重实战,通过具体的案例分析,讲解微信小程序的市场状况、人员分工、小程序需求设计、小程序体验设计、......一起来看看 《微信小程序》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具