After creating a file containing all the users we have to manually check and remove certain users like root, froxlor etc. which might be already configured on the new server by editing the file vim /tmp/mysql_users_grant_queries.sql . The we use the file as input to get the real information.

I know that putting the password in the command line is very insecure, but since we migrate the data and will give up the old server it does not really matter. Then transfer the files to the new server and import them with mysql -uroot -p < <filename>.sql .