There are two simple ways to backup only the users and privileges in MySQL:
1- Using mysqlpump utility (as create user and grant statements):
[shell ~]$ mysqlpump -uUSER -p --exclude-databases=%
--add-drop-user --users >
/tmp/pump-all-users_privileges-timestamp.sql
Dump completed in 1364 milliseconds
Sample output:
[shell ~]$ head
/tmp/pump-all-users_privileges-timestamp.sql
-- Dump created by MySQL pump utility, version: 5.7.21-20, Linux
(x86_64)
-- Dump start time: Sun May 13 23:30:49 2018
-- Server version: 5.7.21
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS,
FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE;
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET …