# How to expert MySQL user account, with password and right permission to another MySQL server

**URL:** https://forums.percona.com/t/how-to-expert-mysql-user-account-with-password-and-right-permission-to-another-mysql-server/7873
**Category:** Database Monitoring and Management
**Tags:** community, mysql, percona
**Created:** [August 10, 2020, 2:21am UTC](https://forums.percona.com/t/how-to-expert-mysql-user-account-with-password-and-right-permission-to-another-mysql-server/7873 "2020-08-10T02:21:21Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![DBA100](https://avatars.discourse-cdn.com/v4/letter/d/b3f665/32.png) [@DBA100](https://forums.percona.com/u/DBA100)
#### Post date: [August 10, 2020, 2:21am UTC](https://forums.percona.com/t/how-to-expert-mysql-user-account-with-password-and-right-permission-to-another-mysql-server/7873/1 "2020-08-10T02:21:21Z")

</div>

Hi,  
As we are going to migrate from percona xtradB cluster 5.7x to 8.0.19, may I know how toexpert MySQL user account, with password and right permission to another MySQL server?  
I planned to use;  
mysqldump  
–host=\<DB host we want to back from \> --all-databases --events  
–routines --triggers --replace --master-data=2 \>  
\<dump\_file.sql\>  
to backup everything from existing mysql to the new one, but what I know is this command do not have back username and password as well as permission to the new percona xtraDB cluster 8.0.19 ?  
  
by restore I use this one:  
mysql --host=\<DB host we want to  
restore to \> -u root -p \< \<dump\_file.sql\>  
  
any idea on how to copy username and password to another MySQL server?

---

<div class="post-metadata">

### Author: ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)
#### Post date: [August 11, 2020, 7:56pm UTC](https://forums.percona.com/t/how-to-expert-mysql-user-account-with-password-and-right-permission-to-another-mysql-server/7873/2 "2020-08-11T19:56:46Z")

</div>

The best tool for this comes from the Percona Toolkit, [pt-show-grants](https://www.percona.com/doc/percona-toolkit/LATEST/pt-show-grants.html)  
Install the toolkit and use this tool to securely copy users and their hashed passwords to another mysql server.

---

<div class="post-metadata">

### Author: ![DBA100](https://avatars.discourse-cdn.com/v4/letter/d/b3f665/32.png) [@DBA100](https://forums.percona.com/u/DBA100)
#### Post date: [August 20, 2020, 5:40am UTC](https://forums.percona.com/t/how-to-expert-mysql-user-account-with-password-and-right-permission-to-another-mysql-server/7873/3 "2020-08-20T05:40:43Z")

</div>

how about mysqlpump ? it seems it is better ?

---

<div class="post-metadata">

### Author: ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)
#### Post date: [August 20, 2020, 8:28am UTC](https://forums.percona.com/t/how-to-expert-mysql-user-account-with-password-and-right-permission-to-another-mysql-server/7873/4 "2020-08-20T08:28:07Z")

</div>

> [@](#):
>
> [https://dev.mysql.com/doc/refman/8.0/en/mysqlpump.html](https://dev.mysql.com/doc/refman/8.0/en/mysqlpump.html "Link: https://dev.mysql.com/doc/refman/8.0/en/mysqlpump.html")  
> By default,&nbsp;[**mysqlpump**](https://dev.mysql.com/doc/refman/8.0/en/mysqlpump.html)&nbsp;does not dump user account definitions, even if you dump the&nbsp;mysql&nbsp;system database that contains the grant tables.&nbsp;

Not for user accounts without modification. pt-show-grants would be easier to get a copy of all the user accounts and simply copy/paste from A-\>B

---

<div class="post-metadata">

### Author: ![DBA100](https://avatars.discourse-cdn.com/v4/letter/d/b3f665/32.png) [@DBA100](https://forums.percona.com/u/DBA100)
#### Post date: [August 21, 2020, 12:54am UTC](https://forums.percona.com/t/how-to-expert-mysql-user-account-with-password-and-right-permission-to-another-mysql-server/7873/5 "2020-08-21T00:54:19Z")

</div>

I said that as some of&nbsp; your member said mysqlpump is the best and my test is ok with mysqlpump too !  
“pt-show-grants would be easier to get a copy of all the user accounts and simply copy/paste from A-\>B”  
e.g. this&nbsp; ?

```auto
pt-show-grants --separate --revoke | diff othergrants.sql -

```

---

<div class="post-metadata">

### Author: ![DBA100](https://avatars.discourse-cdn.com/v4/letter/d/b3f665/32.png) [@DBA100](https://forums.percona.com/u/DBA100)
#### Post date: [August 21, 2020, 1:11am UTC](https://forums.percona.com/t/how-to-expert-mysql-user-account-with-password-and-right-permission-to-another-mysql-server/7873/6 "2020-08-21T01:11:39Z")

</div>

or as from this link&nbsp;[https://serverfault.com/questions/8860/how-can-i-export-the-privileges-from-mysql-and-then-import-to-a-new-server/399875#399875](https://serverfault.com/questions/8860/how-can-i-export-the-privileges-from-mysql-and-then-import-to-a-new-server/399875#399875),&nbsp;

```auto
MYSQL_CONN="-uroot -ppassword"
mysql ${MYSQL_CONN} --skip-column-names -A -e"SELECT CONCAT('SHOW GRANTS FOR ''',user,'''@''',host,''';') FROM mysql.user WHERE user&lt;&gt;''" | mysql ${MYSQL_CONN} --skip-column-names -A | sed 's/$/;/g' &gt; MySQLUserGrants.sql

then I just execute MySQLUserGrants.sql, which will create all user with password and respective grants?

```

---

<div class="post-metadata">

### Author: ![DBA100](https://avatars.discourse-cdn.com/v4/letter/d/b3f665/32.png) [@DBA100](https://forums.percona.com/u/DBA100)
#### Post date: [August 21, 2020, 1:26am UTC](https://forums.percona.com/t/how-to-expert-mysql-user-account-with-password-and-right-permission-to-another-mysql-server/7873/7 "2020-08-21T01:26:22Z")

</div>

[I](https://serverfault.com/questions/8860/how-can-i-export-the-privileges-from-mysql-and-then-import-to-a-new-server/399875#399875)&nbsp;also see from the same link, both of them works perfectly?

METHOD #1

You can use&nbsp;[**pt-show-grants**](http://www.percona.com/doc/percona-toolkit/2.0/pt-show-grants.html)&nbsp;from Percona Toolkit

```auto
MYSQL_CONN="-uroot -ppassword"
pt-show-grants ${MYSQL_CONN} &gt; MySQLUserGrants.sql

```

METHOD #2

You can emulate&nbsp;pt-show-grants&nbsp;with the following

``` MYSQL_CONN="-uroot -ppassword" mysql ${MYSQL_CONN} --skip-column-names -A -e"SELECT CONCAT('SHOW GRANTS FOR ''',user,'''@''',host,''';') FROM mysql.user WHERE user\<\>''" | mysql ${MYSQL_CONN} --skip-column-names -A | sed 's/$/;/g' \> MySQLUserGrants.sql ```

---

<div class="post-metadata">

### Author: ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)
#### Post date: [August 21, 2020, 8:29am UTC](https://forums.percona.com/t/how-to-expert-mysql-user-account-with-password-and-right-permission-to-another-mysql-server/7873/8 "2020-08-21T08:29:19Z")

</div>

That’s essentially what pt-show-grants does. Our Percona Toolkit tools are simple wrappers around complex SQL to make things easier. You can do it the complicated way, or the easy way (Percona toolkit)

---

<div class="post-metadata">

### Author: ![DBA100](https://avatars.discourse-cdn.com/v4/letter/d/b3f665/32.png) [@DBA100](https://forums.percona.com/u/DBA100)
#### Post date: [August 27, 2020, 5:03am UTC](https://forums.percona.com/t/how-to-expert-mysql-user-account-with-password-and-right-permission-to-another-mysql-server/7873/9 "2020-08-27T05:03:20Z")

</div>

“or the easy way (Percona toolkit)”  
ahaha.  
  
so my command above is correct?&nbsp;  
so this one: “MYSQL\_CONN=”-uroot -ppassword"" , is set in linux ?&nbsp;

---

<div class="post-metadata">

### Author: ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)
#### Post date: [August 27, 2020, 8:18am UTC](https://forums.percona.com/t/how-to-expert-mysql-user-account-with-password-and-right-permission-to-another-mysql-server/7873/10 "2020-08-27T08:18:52Z")

</div>

You don’t have to do that MYSQL\_CONN variable. Just put the parameters directly within your call to pt-show-grants

```auto
pt-show-grants -uroot -pmypassword &gt;mysqlusegrants.sql

```

---

<div class="post-metadata">

### Author: ![DBA100](https://avatars.discourse-cdn.com/v4/letter/d/b3f665/32.png) [@DBA100](https://forums.percona.com/u/DBA100)
#### Post date: [August 27, 2020, 10:38pm UTC](https://forums.percona.com/t/how-to-expert-mysql-user-account-with-password-and-right-permission-to-another-mysql-server/7873/11 "2020-08-27T22:38:24Z")

</div>

“pt-show-grants -uroot -pmypassword \>mysqlusegrants.sql”  
ok, just one command in linux ? so this means&nbsp;pt-show-grants can only backup username and password and nothing else.  
  
so when restore I have to do :  
mysql -u root -p \<&nbsp;mysqlusegrants.sql&nbsp; ?

---

<div class="post-metadata">

### Author: ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)
#### Post date: [August 27, 2020, 10:47pm UTC](https://forums.percona.com/t/how-to-expert-mysql-user-account-with-password-and-right-permission-to-another-mysql-server/7873/12 "2020-08-27T22:47:35Z")

</div>

\>&nbsp;pt-show-grants can only backup username and password and nothing else  
No. It backs up usernames, passwords, and all GRANTs associated with each user account.  
  
\>so when restore I have to do :  
\> mysql -u root -p \<&nbsp;mysqlusegrants.sql  
Correct

---

<div class="post-metadata">

### Author: ![DBA100](https://avatars.discourse-cdn.com/v4/letter/d/b3f665/32.png) [@DBA100](https://forums.percona.com/u/DBA100)
#### Post date: [August 27, 2020, 10:59pm UTC](https://forums.percona.com/t/how-to-expert-mysql-user-account-with-password-and-right-permission-to-another-mysql-server/7873/13 "2020-08-27T22:59:19Z")

</div>

tks.
