I have several thousand MySQL users all set to allow access from a specific host. The problem is that now I\'m going to have two machines (more in the future) which will nee
I received the same error with RENAME USER and GRANTS aren't covered by the currently accepted solution:
The most reliable way seems to be to run SHOW GRANTS for the old user, find/replace what you want to change regarding the user's name and/or host and run them and then finally DROP USER the old user. Not forgetting to run FLUSH PRIVILEGES (best to run this after adding the new users' grants, test the new user, then drop the old user and flush again for good measure).
> SHOW GRANTS FOR 'olduser'@'oldhost';
+-----------------------------------------------------------------------------------+
| Grants for olduser@oldhost |
+-----------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'olduser'@'oldhost' IDENTIFIED BY PASSWORD '*PASSHASH' |
| GRANT SELECT ON `db`.* TO 'olduser'@'oldhost' |
+-----------------------------------------------------------------------------------+
2 rows in set (0.000 sec)
> GRANT USAGE ON *.* TO 'newuser'@'newhost' IDENTIFIED BY PASSWORD '*SAME_PASSHASH';
Query OK, 0 rows affected (0.006 sec)
> GRANT SELECT ON `db`.* TO 'newuser'@'newhost';
Query OK, 0 rows affected (0.007 sec)
> DROP USER 'olduser'@'oldhost';
Query OK, 0 rows affected (0.016 sec)