以前直接修改mysql.user就ok了,现在不行了,正好虚拟机MySQL的root密码忘记了,就简单记录下:(本方法不适合互联网线上项目,除非你不在意这段时间的损失)

PS:以UbuntuServer为例(CentOS你把配置文件的位置换下就ok了)

坑点:

  1. 不能和以前一样直接修改user表了,需要使用新命令

    • alter user 'root'@'localhost' identified with mysql_native_password by '复合密码强度的新密码';
  2. ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
    • flush privileges;

修改密码

附录

dnt@ubuntuserver:~$ vi /etc/mysql/mysql.conf.d/mysqld.cnf
dnt@ubuntuserver:~$ cat /etc/mysql/mysql.conf.d/mysqld.cnf |grep skip
skip-external-locking
# Instead of skip-networking the default is now to listen only on
skip_name_resolve=on
skip-grant-tables
dnt@ubuntuserver:~$ sudo systemctl restart mysql
dnt@ubuntuserver:~$ mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26-0ubuntu0.18.04.1 (Ubuntu) Copyright (c) 2000, 2019, 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> select user();
+--------+
| user() |
+--------+
| root@ |
+--------+
1 row in set (0.01 sec) mysql> alter user 'root'@'localhost' identified with mysql_native_password by 'WWW.baidu.com1';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec) mysql> alter user 'root'@'localhost' identified with mysql_native_password by 'WWW.baidu.com1';
Query OK, 0 rows affected (0.00 sec) mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec) mysql> exit
Bye

恢复正常

附录

dnt@ubuntuserver:~$ sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
dnt@ubuntuserver:~$ cat /etc/mysql/mysql.conf.d/mysqld.cnf |grep skip
skip-external-locking
# Instead of skip-networking the default is now to listen only on
skip_name_resolve=on
# skip-grant-tables
dnt@ubuntuserver:~$ sudo systemctl restart mysql
dnt@ubuntuserver:~$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26-0ubuntu0.18.04.1 (Ubuntu) Copyright (c) 2000, 2019, 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> select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)

MySQL5.7.26 忘记Root密码小计的更多相关文章

  1. mysql 5.7.26 忘记root密码

    1.关闭mysql [root@mysql ~]# /etc/init.d/mysqld stopShutting down MySQL.. SUCCESS! 2.修改参数文件/etc/my.cnf ...

  2. MySQL5.7 忘记root密码,怎么破?

    MySQL5.7 忘记root密码,怎么破? 关服 # kill $mysql_pid 免密启动 # /usr/local/mysql57/bin/mysqld_safe --defaults-fil ...

  3. Linux忘记root密码怎么办?

    开篇前言:Linux系统的root账号是非常重要的一个账号,也是权限最大的一个账号,但是有时候忘了root密码怎么办?总不能重装系统吧,这个是下下策,其实Linux系统中,如果忘记了root账号密码, ...

  4. Mac上MySQL忘记root密码且没有权限的处理办法&workbench的一些tips (转)

    忘记Root密码肿么办 Mac上安装MySQL就不多说了,去mysql的官网上下载最新的mysql包以及workbench,先安装哪个影响都不大.如果你是第一次安装,在mysql安装完成之后,会弹出来 ...

  5. mysql 免安装与 忘记root密码 密码过期

    免安装: 参考 :https://blog.csdn.net/werwqerwerwer/article/details/52919939 注:别忘了配置环境变量   忘记root密码解决办法: 1. ...

  6. 忘记root密码怎么办-单用户模式修改root密码

    忘记root密码怎么办-单用户模式修改root密码================================= 1,开机3秒内按下向下的方向键,目的是为了不让它进入系统,而是停留在开机界面. 2 ...

  7. CentOS6.5的安装及忘记root密码的措施

    CentOS6.5的安装及忘记root密码的措施 VMware虚拟机的配置 1.文件->新建->自定义->下一步 2.选择稍后安装操作系统 我们将采用自定义安装,杜绝VMware的一 ...

  8. mysql-管理命令【创建用户、授权、修改密码、删除用户和授权、忘记root密码】

    一.创建用户 命令: CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 关键参数说明: username - 创建登录用户名, host ...

  9. mysql忘记root密码连接本地库

    http://www.cnblogs.com/zf2011/archive/2012/03/13/2393387.html 今天想做个小项目,决定用mysql数据库,但是好久没用mysql了,也忘掉了 ...

随机推荐

  1. Angular 学习笔记——ng-disable

    <!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <met ...

  2. Windows局域网如何进行远程桌面连接

    我们以虚拟机为例: 1 确保被控制的计算机允许远程连接   2 确保被控制的计算机有密码(一般人方便,只有一个administrator账号,而且不设密码,开机直接进入的,如果没有密码,将无法进行远程 ...

  3. functools.wraps

    我们在使用 Decorator 的过程中,难免会损失一些原本的功能信息.直接拿 stackoverflow 里面的栗子     1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...

  4. 如何在Django1.6结合Python3.3版本中使用MySql

    用起了Python3.4跟Django1.6,数据库依然是互联网企业常见的MySql. 悲催的是在Python2.7时代连接MySql的MySQLdb还不支持Python3.4,还好,苦苦追问G哥终于 ...

  5. 【C/C++学院】0828-数组与指针/内存分配/数据结构数组接口与封装

    [送给在路上的程序猿] 对于一个开发人员而言,可以胜任系统中随意一个模块的开发是其核心价值的体现. 对于一个架构师而言,掌握各种语言的优势并能够运用到系统中.由此简化系统的开发,是其架构生涯的第一步. ...

  6. MySQL中创建用户分配权限

    测试环境:CentOS6.8 和 MySQL5.5.4 一 需求 在项目开发的过程中可能需要开放自己的数据库给别人,但是出于安全的考虑,不能同时开放自己服务器里的其他数据库.那么可以新建一个用户,赋予 ...

  7. ASP.NET综合管理ERP系统100%源代码+所有开发文档

    该系统开发环境为:VS2010,数据库採用SQL Server,框架为ASP.NET. 源代码包含所有文档说明,代码简单易懂,凝视完整. 提示:假设没有安装水晶报表系统执行会报错,报表安装程序已经打包 ...

  8. 无法将“Update-Database”项识别为 cmdlet、函数、脚本文件或可运行程序的名称的问题

    原因: 没有引用EntityFramework命令 解决: 在程序包管理器控制台执行如下命令:Import-Module 项目路径\packages\EntityFramework.6.1.3(EF版 ...

  9. [linux]top命令详解-实时显示系统中各个进程的资源占用状况

    简介 top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器. top显示系统当前的进程和其他状况,是一个动态显示过程,即可以通过用户按 ...

  10. sql server 执行大.sql文件

    打开cmd执行:osql -S 127.0.0.1 -U sa -P sa -i d:\test.sql 执行后会提示输入密码.