Skip to content

RootDBA

DBA expertise: PostgreSQL, SQL Server & MySQL

Menu
  • Home
  • blog
  • PostgreSql
  • MySql
  • Sql Server
  • About AHMED – Root DBA
Menu

MySQL to MySQL Migration Guide

Posted on September 2, 2025 by AHMED

The steps involve installing Percona Toolkit to be able to use the Percona tool pt-show-grant. The tool will print out the users with their privileges and encrypted passwords. The following are the steps needed to successfully migrate a MySQL database and users to another MySQL server:

1. installing perocna toolkit

to install persona tool kit download rpm package
we can use wget to download
https://www.percona.com/software/database-tools/percona-toolkit
b8317e7cfc7d9166d7f193a6367b2705.png
select the version and the correct OS version , then copy link from download button , we will use it along side wget
wget https://downloads.percona.com/downloads/percona-toolkit/3.5.7/binary/redhat/8/x86_64/percona-toolkit-3.5.7-1.el8.x86_64.rpm?_gl=1*2fna65*_gcl_au*MTA0Mzk1MDYyOS4xNzE1NjkwMzk5

cd7e372c4b3f83f654f0774ed6842127.png

use yum localinstall to install percona toolkit

sudo yum localinstall 'percona-toolkit-3.5.7-1.el8.x86_64.rpm?_gl=1*2fna65*_gcl_au*MTA0Mzk1MDYyOS4xNzE1NjkwMzk5'

2. change print of hached password to hexadecimal

When using pt-show-grant, MySQL will print the password in a format that cannot be executed on the other side. To resolve this, you need to set the global variable PERSIST.print_identified_with_as_hex to 1. First, log in to MySQL and then execute the following command:

SET @@PERSIST.print_identified_with_as_hex = 1;

52fa4719b698fad95e11fcf0384e214b.png

3.print login and move them to another server

now we can start print out the login , for this steps we will print the login to file and then use scp to move the login to other side server

now we will print out the user to file called user.sql

pt-show-grants -uroot -p[password] > user.sql

0f5f9e67c06e9d0db967762f65be5bae.png

now we will move the file to other side server

scp user.sql [email protected]:/home/appuser/STGmigr/

399c6ad07a13255a7c4464cf89bad994.png

4.apply the logins to the destination MySQL server

note : make sure to apply the user logins after migrating the databases, since some logins may have permissions on specific databases or tables.

Since we have moved the login file to the destination MySQL server, we will start applying the logins. It is best practice to apply the logins manually to avoid overriding system users and the root user on the destination MySQL server.

first use cat to read content of the file
cat user.sql
bd1512a0b024c010223f9142cc3d4c80.png

the file separate each user with the sentence -- Grants for
we should avoid system user and root user
we will start with the below normal user and apply them
a0692ca41c6a1c195c1e3ab940e4fae0.png

The syntax for users will contain CREATE USER, followed by ALTER USER on the next line to define the password. We should reconstruct the query to include CREATE USER along with the password definition.

below example

orginial query

CREATE USER IF NOT EXISTS `user_3a4b5c6d`@`localhost`;
ALTER USER `user_3a4b5c6d`@`localhost` IDENTIFIED WITH 'caching_sha2_password' AS 0x244124303035247F65742B482D117D3E4E25343D3C503B607A063D5877615662393562544355376D65426B7A6A624D7753657867544C334A3161366170432E7479567A715838 REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT PASSWORD REQUIRE CURRENT DEFAULT

query after

CREATE USER IF NOT EXISTS `user_3a4b5c6d`@`localhost` IDENTIFIED WITH 'caching_sha2_password' AS 0x244124303035247F65742B482D117D3E4E25343D3C503B607A063D5877615662393562544355376D65426B7A6A624D7753657867544C334A3161366170432E7479567A715838 REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK PASSWORD HISTORY DEFAULT PASSWORD REUSE INTERVAL DEFAULT PASSWORD REQUIRE CURRENT DEFAULT

we simple taking merged the create user and alter user to gather to constructed single query

now we will execute the query MySQL
760ffa6c51a014daa0469d1c2f1b066c.png

now we will execute the user grants

GRANT APPLICATION_PASSWORD_ADMIN,AUDIT_ABORT_EXEMPT,AUDIT_ADMIN,AUTHENTICATION_POLICY_ADMIN,BACKUP_ADMIN,BINLOG_ADMIN,BINLOG_ENCRYPTION_ADMIN,CLONE_ADMIN,CONNECTION_ADMIN,ENCRYPTION_KEY_ADMIN,FIREWALL_EXEMPT,FLUSH_OPTIMIZER_COSTS,FLUSH_STATUS,FLUSH_TABLES,FLUSH_USER_RESOURCES,GROUP_REPLICATION_ADMIN,GROUP_REPLICATION_STREAM,INNODB_REDO_LOG_ARCHIVE,INNODB_REDO_LOG_ENABLE,PASSWORDLESS_USER_ADMIN,PERSIST_RO_VARIABLES_ADMIN,REPLICATION_APPLIER,REPLICATION_SLAVE_ADMIN,RESOURCE_GROUP_ADMIN,RESOURCE_GROUP_USER,ROLE_ADMIN,SENSITIVE_VARIABLES_OBSERVER,SERVICE_CONNECTION_ADMIN,SESSION_VARIABLES_ADMIN,SET_USER_ID,SHOW_ROUTINE,SYSTEM_USER,SYSTEM_VARIABLES_ADMIN,TABLE_ENCRYPTION_ADMIN,TELEMETRY_LOG_ADMIN,XA_RECOVER_ADMIN ON *.* TO `user_3a4b5c6d`@`localhost`;

232aed681e492ce09d278c9919d1a5a2.png

c48c8a0f2ab3bda201b7771ad4ef7447.png

91172310e233de7df7221b71a984f0ae.png

now you can continue doing the same to other account

5. taking database dump backup

For this step, we will take a database dump using the mysqldump tool. While it is possible to take a dump of the entire MySQL server, restoring it on the destination server will override users and other system databases. The best practice is to back up only the user database.

First, list the databases and determine the databases we would like to migrate.

10fa0f83cdf1530bc5ded0ac85579007.png

for this purpose we will be migrating sakila database

a9e149a8d0e12bc19571a601cf757e55.png

then start taking the backup by using the following syntax

mysqldump [options] --databases db1 db2 ..db_name > backup_name.sq

we can mention multiple database but for our purpose we only have one database

mysqldump -uroot -p --databases sakila > backup_sakila.sq

05586957dc7a328615595713e692ec00.png

6 transfer the database and restore it

now we will use scp to transfer the database to destination MySQL server

scp backup_sakila.sq [email protected]:/home/appuser/STGmigr/

8340dd4c12dd8eb97544eaeb262d1a8e.png

next we will restore the database using the below command

mysql -uroot -p < backup_sakila.sq

a37794ee0caed4868e206312fe91662a.png

29c24a26b862337c4f0062566d60f974.png

0
Visited 78 times, 1 visit(s) today
Category: mysql

Post navigation

← Mysql Perocna Xtradb Cluster Setup Guide
Using percona xtrabackup for backup →
© 2025 RootDBA | Powered by Minimalist Blog WordPress Theme