1. Accidentally deleted mysql All users

mysql> delete from mysql.user where 1=1;
Query OK, 5 rows affected (0.00 sec)
# You can still log in after deleting users , But don't restart 

2. Solution one :

1) Stop database

# Take a cigarette and calm down
[[email protected] scripts]# systemctl stop mysqld

2) Skip authorization table and network startup

[[email protected] scripts]# mysqld_safe --skip-grant-tables --skip-networking &

3) Insert new user

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');

4) Restart the database

[[email protected] scripts]# mysqladmin shutdown
200709 16:27:19 mysqld_safe mysqld from pid file /usr/local/mysql/data/db02.pid ended
[1]+  Done                    mysqld_safe --skip-grant-tables --skip-networking
[[email protected] scripts]# systemctl start mysqld

3. Solution two :

1) Stop database

# Take a cigarette and calm down
[[email protected] scripts]# systemctl stop mysqld

2) Skip authorization table and network startup

[[email protected] scripts]# mysqld_safe --skip-grant-tables --skip-networking &

3) Authorize a new user

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on *.* to [email protected]'localhost' identified by '123' with grant option;
Query OK, 0 rows affected (0.00 sec)