Moving Users on MySQL

Copying users from a database on host1 to a database on host2 under MySQL:
echo "select concat(\"show grants for '\", user,\"'@'\", host, \"';\") from user where host='localhost' or host = '';" | mysql -u root -p --skip-column-names -h host1 mysql | mysql -u root -p --skip-column-names -h host1 mysql | sed 's/$/;/' | mysql -u root -p -h host2


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: