mysql03--误删除了所有用户解决办法
误删除了所有用户解决办法
第一种方法(企业常用)
1.将数据库down掉
[root@db03 mysql]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
[root@db03 mysql]# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/mysql-5.6.44/tmp/mysql.sock' (2)
2.给/opt/目录下所有受mysql用户权限
[root@db03 mysql]# chown -R mysql.mysql /opt/*
3.启动数据库
[root@db03 ~]# mysqld_safe --skip-grant-tables --skip-networking &
4.进入数据库
[root@db03 ~]# mysql
5.初始化
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
6.设置数据库用户权限和密码
mysql> grant all on *.* to root@'localhost' identified by '1' with grant option;
Query OK, 0 rows affected (0.00 sec)
7.退出重启数据库
mysql> \q
[root@db03 mysql]# /etc/init.d/mysqld restar
8.进入数据库查看
mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | localhost |
+------+-----------+
1 row in set (0.01 sec)
第二种方法
1.down掉数据库
[root@db04 scripts]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
2.启动数据库
[root@db04 scripts]# mysqld_safe --skip-grant-tables --skip-networking & [1] 25934
3.进入数据库
[root@db04 scripts]# mysql
4.使用数据库
mysql> use mysql
Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed
5.创建root用户
mysql> insert into mysql.user values ('localhost','root',PASSWORD('123'),
-> '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','','N');
6.查看用户
mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | localhost |
+------+-----------+
1 row in set (0.00 sec)

第三种方法(企业不可用,数据会丢失)
1.down掉数据库
[root@db04 ~]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
2.删除或改名/opt/mysql/data目录
[root@db04 opt]# cd mysql
[root@db04 mysql]# mv data date
[root@db04 mysql]# rm -fr data
3.初始化
[root@db04 scripts]# ./mysql_install_db --datadir=/opt/mysql/data --basedir=/opt/mysql -- user=mysql
[root@db04 scripts]# echo $?
0

4.授权
[root@db04 scripts]# chown -R mysql.mysql /opt/*
5.启动数据库
[root@db04 scripts]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/opt/mysql/data/db04.err'. SUCCESS!
6.进入数据库查看
[root@db04 scripts]# mysql
mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | % |
| root | 127.0.0.1 |
| root | ::1 |
| | db02 |
| root | db02 |
| | localhost |
| root | localhost |
+------+-----------+
7 rows in set (0.00 sec)

mysql03--误删除了所有用户解决办法的更多相关文章
- 误删除 mySQL 用户解决办法
误删除用户解决办法 删除用户 删除用户 mysql> truncate mysql.user;Query OK, 0 rows affected (0.05 sec)mysql> sel ...
- Sql Server 孤立用户解决办法
Sql Server 孤立用户 是我们经常遇到的事情,今天详细的梳理了下,希望能帮到你 当把用户数据库从一台 Sql Server 使用备份和恢复的方式迁移到另一台服务器.数据库恢复以后,原先用户定义 ...
- Oracle 学习笔记3:新建数据库没有scott用户解决办法
新建一个数据库,若选择Oracle组件时,没有选择实例方案,完成后进行口令管理,默认列表中是找不到scott用户解锁的.若要解锁scott用户,可以进行如下操作: 使用system或者sys连接数据库 ...
- centos误删mysql root用户找回办法
一天,我进入mysql后,查看所有用户 select host,user from mysql.user; 发现好多用户名, 太乱了,删除..... delete from user where us ...
- 误删/usr文件夹解决办法
http://blog.chinaunix.net/uid-2623904-id-3044156.html http://www.centoscn.com/CentOS/Intermediate/20 ...
- centos7误删yum源的解决办法 ( -bash: yum: command not found)
这里以安装阿里的yum源为例: 1.查看自己的centos版本 cat /etc/redhat-release 2.进入阿里云源站地址:http://mirrors.aliyun.com/centos ...
- Oracle数据库误删文件导致rman备份报错RMAN-06169解决办法
Oracle数据库误删文件导致rman备份报错RMAN-06169解决办法 可能是误删文件导致在使用rman备份时候出现以下提示 RMAN-06169: could not read file hea ...
- mac 安装mysql + 修改root用户密码 + 及报Access denied for user 'root'@'localhost' (using password:YES)解决办法
1.下载MySQL 到mysql的官网http://dev.mysql.com/downloads/mysql/然后在页面中会看到“MySQL Community Server”下方有一个“downl ...
- "SQLServer无法打开用户默认数据库,登录失败,错误4064"的解决办法
"SQLServer无法打开用户默认数据库,登录失败,错误4064"的解决办法 1.检查登录密码 如果密码错误,修改数据库密码,用windows身份验证登录进去, (1)安全--登 ...
随机推荐
- centos 6.5 安装 subversion
安装subversion需要依赖apr.apr-util.sqlite,下载安装包,放在/usr/file目录 subversion-1.9.4.tar.gz apr-1.5.2.tar.gz apr ...
- springboot 中的 thymeleaf 页面进阶小知识
我们做好了登录页,那设计一个场景吧,比如我们登录后跳转到公司主页,想从公司主页再跳转到员工列表页: 这样的场景我们该如何实现,首先要知道一些基础知识,就是SpringBoot的一些关于请求的架构知识: ...
- [CH5E02] A Little Shop of Flowers
问题描述 You want to arrange the window of your flower shop in a most pleasant way. You have F bunches o ...
- TPS、QPS和系统吞吐量的区别和理解
参考:https://blog.csdn.net/u010889616/article/details/83245695 一.QPS/TPSQPS:Queries Per Second意思是“每秒查询 ...
- php中substr_compare()区分大小写吗
PHP substr_compare() 函数 定义和用法 substr_compare() 函数从指定的开始位置比较两个字符串. 提示:该函数是二进制安全且选择性地对大小写敏感(区分大小写). 语法 ...
- luogu P1047 校门外的树 x
P1047 校门外的树 题目描述 某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是1米.我们可以把马路看成一个数轴,马路的一端在数轴0的位置,另一端在L的位置:数轴上的每个整数点,即0 ...
- git cherry-pick的使用
[Git] Git整理(五) git cherry-pick的使用 2018年07月13日 23:49:16 FightFightFight 阅读数:31649 版权声明:本文为博主原创文章,未 ...
- [CF1056E]Check Transcription
题目:Check Transcription 传送门:http://codeforces.com/contest/1056/problem/E 分析: 1)显然有个$O( \frac{t}{max(c ...
- python测试redis是否可以使用
前提打开redis服务,windows打开方式到redis的安装目录命令行输入redis-server from redis import StrictRedis redis = StrictRedi ...
- (转)原理到实现 | K8S 存储之 NFS
转:https://mp.weixin.qq.com/s/Mrr1Rnl_594Gyyn9fHekjw 1NFS介绍 NFS是Network File System的简写,即网络文件系统,NFS是Fr ...