码迷,mamicode.com
首页 > 其他好文 > 详细

误删除了所有用户解决办法

时间:2019-10-31 22:02:33      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:有用   shu   nat   oca   scripts   --   src   alt   png   

第一种方法(企业常用)

1.将数据库down掉

/etc/init.d/mysqld stop

2.给/opt/目录下所有受mysql用户权限

chown -R mysql.mysql /opt/*

3.启动数据库

mysqld_safe --skip-grant-tables --skip-networking &

4.进入数据库

mysql

5.初始化

mysql> flush privileges;

6.设置数据库用户权限和密码

mysql> grant all on *.* to root@'localhost' identified by '1' with grant option;

7.退出重启数据库

mysql> \q
/etc/init.d/mysqld restart

8.进入数据库查看

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 | 127.0.0.1 |
| root | ::1 |
| | db04 |
| root | db04 |
| | localhost |
| root | localhost |
+------+-----------+
6 rows in set (0.00 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
[root@db04 scripts]# 191031 19:41:10 mysqld_safe Logging to '/opt/mysql/data/db04.err'.
191031 19:41:10 mysqld_safe Starting mysqld daemon with databases from /opt/mysql/data

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)

技术图片

误删除了所有用户解决办法

标签:有用   shu   nat   oca   scripts   --   src   alt   png   

原文地址:https://www.cnblogs.com/chenmiao531759321/p/11773501.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!