The mayor is the leader of the group of officials that run the small Russian town, all of them corrupt. He, along with the rest of them, are terrified at the news that an inspector will soon be coming to their town to check things out.
In many ways, he plays the dupe after Khlestakov arrives and they mistake him for an inspector and do anything he asks including loaning him huge sums of money. After they find this out, the enraged and incredibly humiliated mayor also finds out that the inspector wishes to see him. Immediately.