Export all MySQL users I need export all of a MySQL database users (including permissions) for a migration. There is over 5,000 users, what is the best way to do this?

Should I just dump the mysql.user table?
If you are moving the users to another DB Server running the same major version of MySQL, copying mysql.user is not sufficient. If the users have access to specific databases, copying mysql.user brings the user and the password.

Then, you would have to copy the following


mysql.db for database-level grants
mysql.tables_priv for table-level grants
mysql.columns_priv for column-level grants


Here is logical way to dump it: as SQL GRANT commands !!!

SUGGESTION #1

If you already have Percona Toolkit installed, run pt-show-grants to a text file

GRANT_FILE=MyDatabaseUSers.sql
pt-show-grants -uroot -p &gt; ${GRANT_FILE}


SUGGESTION #2

If you don't have Percona Toolkit and can't wait, here is my personal emulation of it

GRANT_CMDS=/tmp/ShowGrantsToExport.sql
GRANT_FILE=MyDatabaseUSers.sql
MYSQL_USER=root
MYSQL_PASS=rootpassword
MYSQL_CONN="-u${MYSQL_USER} -p${MYSQL_PASS}"
SQL="SELECT CONCAT('SHOW GRANTS FOR ',QUOTE(user),'@',QUOTE(host),';')"
SQL="${SQL} FROM mysql.user WHERE user&lt;&gt;'' AND host&lt;&gt;''"
mysql ${MYSQL_CONN} -ANe"${SQL}" &gt; ${GRANT_CMDS}
mysql ${MYSQL_CONN} &lt; ${GRANT_CMDS} | sed 's/$/;/g' &gt; ${GRANT_FILE}


EPILOGUE

On the new DB Server, after migrating the data, you login to mysql as root and run 

mysql&gt; source MyDatabaseUSers.sql


GIVE IT A TRY !!!