MySQL Utilities

5.28 mysqluserclone — Clone Existing User to Create New User

This utility uses an existing MySQL user account on one server as a template, and clones it to create one or more new user accounts with the same privileges as the original user. The new users can be created on the original server or a different server.

To list users for a server, specify the --list option. This prints a list of the users on the source (no destination is needed). To control how to display list output, use one of the following values with the --format option:


mysqluserclone accepts the following command-line options:


For the --format option, the permitted values are not case-sensitive. In addition, values may be specified as any unambiguous prefix of a valid value. For example, --format=g specifies the grid format. An error occurs if a prefix matches more than one valid value.

The path to the MySQL client tools should be included in the PATH environment variable in order to use the authentication mechanism with login-paths. This permits the utility to use the my_print_defaults tools which is required to read the login-path values from the login configuration file (.mylogin.cnf).

When cloning users that are defined with an authentication plugin, the utility attempts to use the authentication plugin for the destination user(s). The utility issues an error if the plugin is not on the destination machine or is inactive and the operation is aborted. A warning is issued if a password is assigned to a new user when the source user has an authentication plugin. In this case, the utility uses the password and not the authentication plugin for the new user.


To clone joe as sam and sally with passwords and logging in as root on the local machine, use this command:

shell> mysqluserclone --source=root@localhost \
          --destination=root@localhost \
          joe@localhost sam:secret1@localhost sally:secret2@localhost
# Source on localhost: ... connected.
# Destination on localhost: ... connected.
# Cloning 2 users...
# Cloning joe@localhost to user sam:secret1@localhost
# Cloning joe@localhost to user sally:secret2@localhost
# ...done.

The following command shows all users on the local server in the most verbose output in CSV format:

shell> mysqluserclone --source=root@localhost --list --format=csv -vvv
# Source on localhost: ... connected.


The account used on the source server must have privileges to read the mysql database. The account used to connect to the destination server must have privileges to execute CREATE USER (and DROP USER if the --force option is given), and privileges to execute GRANT for all privileges to be granted to the new accounts.