Mysql – Add host to existing user @ Mysql with the same permission

authenticationMySQL

I would like to add another host for existing users at my DB. I want this new record to have a same privileges with the existing user as well. I saw this thread https://stackoverflow.com/questions/19281305/adding-new-host-entries-to-existing-mysql-users but it seems it does not copy the whole privileges that the existing users have. Any programmatic solution instead of manually adding the user one by one?

Best Answer

If you can install or already have the MySQL Utilities, then you can use the mysqluserclone script.

Reference: 5.28 mysqluserclone — Clone Existing User to Create New User

The command is then a simple:

shell> mysqluserclone --source=root@localhost --destination=root@localhost \
      source_user@localhost target_user:secret1@192.168.1.1

In the above example you are connecting to root@localhost (as the source) and root@localhost (as the target) and are then copying the permissions from source_user@localhost to target_user@192.168.1.1.

So you could use:

shell> mysqluserclone --source=root@localhost --destination=root@localhost \
      Reynaldi@localhost Reynaldi:secret1@192.168.1.1

Further details can be found in the rather limited documentation.