可以通过添加--ship-grant-tables参数来跳过权限表。

1、忘记root密码,进不去数据库:

这个时候需要强制停库,先查看MySQL进程号

Kill掉MySQL进程,命令如下:

Kill完可以再查看是否还有进程

[root@tse2 tmp]# kill -9 9840 1[root@tse2 tmp]# ps -ef |grep mysql

然后加跳过权限表参数,重启数据库。这样即使不输入密码,也可以进入数据库。

[root@tse2 bin]# mysqld_safe --defaults-file=/etc/my.cnf --skip-grant-tables &[1] 4854

给root用户设置新的密码并刷新权限,MySQL5.7之后,库下的password字段用authentication_string字段代替。

(product)root@localhost:mysql.sock [(none)]> use mysql;Database changed(product)root@localhost:mysql.sock [mysql]> update user set authentication_string=password('123456') where user='root';Query OK, 0 rows affected, 1 warning (0.00 sec)Rows matched: 1  Changed: 0  Warnings: 1(product)root@localhost:mysql.sock [mysql]> flush privileges;Query OK, 0 rows affected (0.00 sec)
[root@tse2 bin]# mysqld_safe --deaults-file=/etc/my.cnf &[2] 6720[root@tse2 bin]# 2020-01-16T02:55:45.223195Z mysqld_safe Logging to '/mysql/mysql3306/logs/error.log'.2020-01-16T02:55:45.262302Z mysqld_safe A mysqld process already exists[2]+  Exit 1                  mysqld_safe --deaults-file=/etc/my.cnf[root@tse2 bin]# mysqlERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

[root@tse2 bin]# mysql -uroot -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.7.23-log MySQL Community Server (GPL)Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.(product)root@localhost:mysql.sock [(none)]> use mysqlDatabase changed(product)root@localhost:mysql.sock [mysql]> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || sys                |+--------------------+4 rows in set (0.01 sec)

更多相关文章

  1. MySQL系列多表连接查询92及99语法示例详解教程
  2. Linux下MYSQL 5.7 找回root密码的问题(亲测可用)
  3. MySQL 什么时候使用INNER JOIN 或 LEFT JOIN
  4. ES6 变量声明,箭头函数,数组方法,解构赋值,JSON,类与继承,模块化练习
  5. 浅谈Java中Collections.sort对List排序的两种方法
  6. Python list sort方法的具体使用
  7. python list.sort()根据多个关键字排序的方法实现
  8. android上一些方法的区别和用法的注意事项
  9. android实现字体闪烁动画的方法

随机推荐

  1. android:padding和android:margin的区别
  2. Handler&Looper
  3. Android 创建服务器 NanoHttpd
  4. 关于Android菜单上的记录
  5. android仿今日头条App、多种漂亮加载效果
  6. 开放平台的Android SDK
  7. android Switch控件
  8. Android日记之2012/02/10——Android中的
  9. Android(安卓)NDK开发详细介绍
  10. Android真响应式架构——数据流动性