Script restoregrants which is available in /usr/local/cpanel/bin/restoregrants location helps to restore database users from data which is available in /var/cpanel/databases/grants_* files.
You can use below command:
/usr/local/cpanel/bin/restoregrants [--cpuser=cpuser] [--db=mysql|pg]...