[Share Experiences] Documenting a MySQL Database Migration
Tofloor
poster avatar
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:

  1. Although I have tested this, I cannot guarantee success. Please proceed with caution.
  2. 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.

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 — 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.

Reply Favorite View the author
All Replies

No replies yet