目录

1.前言

2.首先修改my.con配置,设置跳过授权模式

3. 登录MYSQL建表

3. 重启mysql

4. 修改为自己的密码

5. 引用


1.前言

2.首先修改my.con配置,设置跳过授权模式

因为user表被删粗无法进入数据库,设置跳过授权模式登录mysql

进入/etc/my.cnf  (其他版本也可能在/usr/my.cnf)

##  添加跳过授权登录:
skip-grant-tables 

3. 登录MySQL, 建表

直接mysql即可登录

建表语句

CREATE TABLE `user` (`Host` char(60) COLLATE utf8_bin NOT NULL DEFAULT '',`User` char(32) COLLATE utf8_bin NOT NULL DEFAULT '',`Select_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Insert_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Update_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Delete_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Create_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Drop_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Reload_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Shutdown_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Process_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`File_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Grant_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`References_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Index_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Alter_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Show_db_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Super_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Create_tmp_table_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Lock_tables_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Execute_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Repl_slave_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Repl_client_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Create_view_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Show_view_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Create_routine_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Alter_routine_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Create_user_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Event_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Trigger_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`Create_tablespace_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`ssl_type` enum('','ANY','X509','SPECIFIED') CHARACTER SET utf8 NOT NULL DEFAULT '',`ssl_cipher` blob NOT NULL,`x509_issuer` blob NOT NULL,`x509_subject` blob NOT NULL,`max_questions` int(11) unsigned NOT NULL DEFAULT '0',`max_updates` int(11) unsigned NOT NULL DEFAULT '0',`max_connections` int(11) unsigned NOT NULL DEFAULT '0',`max_user_connections` int(11) unsigned NOT NULL DEFAULT '0',`plugin` char(64) COLLATE utf8_bin NOT NULL DEFAULT 'mysql_native_password',`authentication_string` text COLLATE utf8_bin,`password_expired` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',`password_last_changed` timestamp NULL DEFAULT NULL,`password_lifetime` smallint(5) unsigned DEFAULT NULL,`account_locked` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N',PRIMARY KEY (`Host`,`User`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Users and global privileges' 

数据装载语句 (这是我的数据 账号: root  密码: 000000)

INSERT INTO `user` (`Host`, `User`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`, `Create_view_priv`, `Show_view_priv`, `Create_routine_priv`, `Alter_routine_priv`, `Create_user_priv`, `Event_priv`, `Trigger_priv`, `Create_tablespace_priv`, `ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject`, `max_questions`, `max_updates`, `max_connections`, `max_user_connections`, `plugin`, `authentication_string`, `password_expired`, `password_last_changed`, `password_lifetime`, `account_locked`) VALUES ('%', 'root', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', 0, 0, 0, 0, 'mysql_native_password', 0x2A30333231393741453537333144343636343932314136434341433743464345364130363938363933, 'N', '2021-11-22 18:17:35', NULL, 'N');
INSERT INTO `user` (`Host`, `User`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`, `Create_view_priv`, `Show_view_priv`, `Create_routine_priv`, `Alter_routine_priv`, `Create_user_priv`, `Event_priv`, `Trigger_priv`, `Create_tablespace_priv`, `ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject`, `max_questions`, `max_updates`, `max_connections`, `max_user_connections`, `plugin`, `authentication_string`, `password_expired`, `password_last_changed`, `password_lifetime`, `account_locked`) VALUES ('localhost', 'mysql.sys', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', '', '', '', '', 0, 0, 0, 0, 'mysql_native_password', 0x2A5448495349534E4F544156414C494450415353574F52445448415443414E42455553454448455245, 'N', '2021-11-22 18:03:26', NULL, 'Y');
INSERT INTO `user` (`Host`, `User`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`, `Create_view_priv`, `Show_view_priv`, `Create_routine_priv`, `Alter_routine_priv`, `Create_user_priv`, `Event_priv`, `Trigger_priv`, `Create_tablespace_priv`, `ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject`, `max_questions`, `max_updates`, `max_connections`, `max_user_connections`, `plugin`, `authentication_string`, `password_expired`, `password_last_changed`, `password_lifetime`, `account_locked`) VALUES ('%', 'maxwell', 'Y', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'Y', 'Y', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', '', '', '', '', 0, 0, 0, 0, 'mysql_native_password', 0x2A42344338334143333545443831413834454333423239304134454641323631323230333143463633, 'N', '2021-11-23 10:29:02', NULL, 'N');
INSERT INTO `user` (`Host`, `User`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`, `Create_view_priv`, `Show_view_priv`, `Create_routine_priv`, `Alter_routine_priv`, `Create_user_priv`, `Event_priv`, `Trigger_priv`, `Create_tablespace_priv`, `ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject`, `max_questions`, `max_updates`, `max_connections`, `max_user_connections`, `plugin`, `authentication_string`, `password_expired`, `password_last_changed`, `password_lifetime`, `account_locked`) VALUES ('%', 'dolphinscheduler', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', '', '', '', '', 0, 0, 0, 0, 'mysql_native_password', 0x2A37334332464642464332353136304535363844434545424335304242423333433545354230454446, 'N', '2021-12-11 19:03:42', NULL, 'N');
INSERT INTO `user` (`Host`, `User`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`, `Create_view_priv`, `Show_view_priv`, `Create_routine_priv`, `Alter_routine_priv`, `Create_user_priv`, `Event_priv`, `Trigger_priv`, `Create_tablespace_priv`, `ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject`, `max_questions`, `max_updates`, `max_connections`, `max_user_connections`, `plugin`, `authentication_string`, `password_expired`, `password_last_changed`, `password_lifetime`, `account_locked`) VALUES ('%', 'canal', 'Y', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'Y', 'Y', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', '', '', '', '', 0, 0, 0, 0, 'mysql_native_password', 0x2A45333631393332314331413933374334364130443842443144414333394639334232374434343538, 'N', '2021-12-20 19:59:33', NULL, 'N');

3. 重启mysql

刷写 == 关闭跳过授权模式 == 重启mysql = 即可登录

-- 刷写
mysql> flush privileges;
-- 重启mysql,在mysql外执行
service mysqld restart
-- 登录
mysql -uroot -p000000

4. 修改为自己的密码

临时更改密码策略

mysql> set global validate_password_length=4;
mysql> set global validate_password_policy=0;

更改密码

1 mysql> update user set authentication_string=passworD("123456") where user='root';

问题解决!

5. 准备添加的内容

从同版本mysql的其他电脑获取建表语句和数据装载语句, 防止因表结构不同造成的无法使用

其实即使不同也能使用,也能创建其他用户,  但是当其他框架使用mysql时, 有可能造成无访问权限的问题.

6. 引用

MySQL user表被删除了怎么办 - 耿小厨 - 博客园

​​​​​​MYsql数据库误删mysql下的user内容,导致哪哪都不能登录 - 肚子咕咕叫是不是饿了 - 博客园

Linux下修改Mysql密码的三种方式 - 牛奔 - 博客园

Linux中MySQL(5.7版本) user表被删除,解决办法相关推荐

  1. Linux中mount:you must specify the filesystem type解决办法

    问题:挂载U盘时出现以下问题: [root@localhost dev]# mount /dev/sdb1 /tmp/upan mount: you must specify the filesyst ...

  2. linux中mysql的库、表和字段的字符集指令总结

    一.查看数据库,表,字段编码 1.查看数据库编码 (1)通过show variables查看编码,需要转换数据库,不转换看的是server字符集.字符序. mysql> use test; my ...

  3. linux mysql内网_在Linux中mysql的一些基本操作

    在Linux中mysql的一些基本操作 下面介绍一下 一.关于在Linux中mysql的一些基本操作 1.进入mysql "mysql -uroot -p",会提示输入密码,输入密 ...

  4. linux中mysql群集_阅读无群集可用性组中的Scale可用性组

    linux中mysql群集 In this article, we will explore configuring Read Scale Availability Group that does n ...

  5. linux连接本机mysql数据库,Linux中MySQL连接本机数据库客户端

    Linux中MySQL连接本机数据库客户端 Linux中MySQL连接本机数据库客户端 1.登入mysql数据库 2.找到要修改的位置 // 选定要用的数据库(用show databases;看完再u ...

  6. linux mysql异地备份工具,Linux中MySQL的异地自动备份

    Linux中MySQL的异地自动备份 文/李来祥 [摘要]@@ 随着校园网应用的日益丰富,Linux系统下MySQL数据库的应用也越来越广泛.然而数据的意外丢失对于校园网应用来说是很大的损失,业务数据 ...

  7. mysql 备份脚本 linux,LINUX中MySQL如何按时备份脚本

    LINUX中MySQL如何按时备份脚本 发布时间:2020-06-02 17:09:34 来源:51CTO 阅读:212 作者:三月 本篇文章给大家主要讲的是关于LINUX中MySQL如何按时备份脚本 ...

  8. Linux中Mysql root用户看不到mysql库问题解决方式

    Linux中Mysql root用户看不到mysql库问题解决方式 参考文章: (1)Linux中Mysql root用户看不到mysql库问题解决方式 (2)https://www.cnblogs. ...

  9. Linux 中Mysql出现‘> 如何退出?

    Linux 中Mysql出现'> 如何退出? 直接输入\c,就退出了 '> '> '> \c mysql> 这个经过我的测试,有的时候\c不好用.当出现不好用的情况的时候 ...

最新文章

  1. 工行分布式数据库选型与大规模容器化实践
  2. springboot简易集成mybatisPlus+多数据源
  3. 计算机应用网站设计,《计算机应用基础》课程网站的设计与实现
  4. Java编程的逻辑 (59) - 文件和目录操作
  5. Linux报错:Syntax error: ( unexpected解决办法(转)
  6. 近年NOIP普及组复赛题目的简单讲解
  7. Java Bean + 注册验证
  8. python predict_对Keras中predict()方法和predict_classes()方法的区别说明
  9. C++ std::lock_guard 自动加锁、释放锁 原理
  10. 安装多个mysql实例(debian版本)
  11. skiplist及Java实现
  12. setup maven plugin connection
  13. Web前端满屋花案例框架
  14. [BJDCTF2020]Mark loves cat(3种解法)
  15. 生存分析统计方法选择,可以避免的一些坑
  16. 服务器开机一进系统就黑屏,win7系统开机在欢迎界面直接黑屏怎么办
  17. java 实现邮件带附件发送
  18. 学号 20172326 《程序设计与数据结构》第八周学习总结
  19. MATLAB(SimMechanics)机器人可视化运动仿真-关节位置控制篇
  20. ivm 无法播放 解决

热门文章

  1. 太阳能光热产业发展现状及趋势
  2. 破解闲鱼收货源代码 详细解析
  3. 青柚im安装短信宝短信插件教程
  4. 蓝桥省赛 包子凑数 完全背包
  5. Office PowerPoint之ppt动画版DUANG!!!
  6. 科学计算机显示math,Math在科学计算器上代表什么怎样才能在计算器上显示?
  7. 2015年度-渐入佳境
  8. Zookeeper: 一个分布式应用程序协调服务
  9. MATLAB中图像的保存
  10. Spring是什么?一文带你快速入门Spring