[Share Experiences] Documenting a MySQL Database Migration
Experiences and Insight 255 views · 0 replies ·
SuperDavid
Moderator
2024-09-09 15:31
Author
Documenting a MySQL Database Migration
MySQL Database Migration
The content might seem trivial and may not be useful for everyone.
(Recently, I reinstalled my system and needed to migrate the already set up environment, including MySQL, so I researched this topic.)
I noticed some users on the forum or elsewhere might be using MySQL databases and might need this information. If this post doesn't help you, feel free to skip it.
Note:
Although I have tested this, I cannot guarantee success. Please proceed with caution.
The database versions were the same during my migration. Cross-version migration success is unknown.
Determine the database you want to migrate
In MySQL:
SHOW DATABASES;
This command displays all the databases in MySQL. Choose the one you need to migrate.
Note: If you need to backup multiple databases, you must export them separately, each database corresponding to one SQL file. It is recommended to include the default character set parameter, such as --default-character-set=utf8 — waittingsummer
Create the corresponding database in the destination MySQL
In MySQL:
CREATE DATABASE [database_to_migrate];
Note: The database name must be the same as the original one.
Import the data
Shell command:
mysql -u [username] -p [database_name] < [exported_database].sql
The original database is also required for the import.
Documenting a MySQL Database Migration
MySQL Database Migration
The content might seem trivial and may not be useful for everyone.
(Recently, I reinstalled my system and needed to migrate the already set up environment, including MySQL, so I researched this topic.)
I noticed some users on the forum or elsewhere might be using MySQL databases and might need this information. If this post doesn't help you, feel free to skip it.
Note:
Determine the database you want to migrate
In MySQL:
SHOW DATABASES;
This command displays all the databases in MySQL. Choose the one you need to migrate.
Export the database
Shell command:
mysqldump -u [username] -p [database_to_backup] > [exported_database].sql
Note: If you need to backup multiple databases, you must export them separately, each database corresponding to one SQL file. It is recommended to include the default character set parameter, such as
--default-character-set=utf8
— waittingsummerCreate the corresponding database in the destination MySQL
In MySQL:
CREATE DATABASE [database_to_migrate];
Note: The database name must be the same as the original one.
Import the data
Shell command:
mysql -u [username] -p [database_name] < [exported_database].sql
The original database is also required for the import.