
Migrating a local MySQL Database to Vultr Managed Databases for MySQL is a good practice that implements remote accessibility, increased security, high availability, minimal maintenance, and administration for your database.
In this article, you'll learn how to migrate an on-premise MySQL database to a Vultr Managed Database cluster.
To successfully migrate the database, you need to:
SELECT, VIEW, TRIGGER, and LOCK TABLES privileges on the local database.mysqldump is a backup utility that stores MySQL databases in the form of SQL statements used to reproduce the original database when executed. In this section, you'll back up a single database to a file and import it to a managed database.
Log in to your local MySQL database server. Replace dbuser with your actual database user.
Show databases, and keep note of the database name you intend to export.
Exit the MySQL console.
Stop all services using the local database to prevent modifications during export. Services that use the local database will be offline during the migration.
Using the mysqldump utility, export a single database to a file.
To export all databases, run the following:
Exporting may take some time to complete depending on your database size.
If you prefer to use PHPMyAdmin instead of the MySQL client tool, export your database as follows:
Log in to PHP MyAdmin
Select your target database from the left navigation panel.
Click Export on the top navigation menu.
Choose your desired export method, Quick or Custom.
Click GO to start exporting and download the database file.
Keep note of the downloaded file location. You'll use the MySQL client tool to import the database to your Vultr managed database.
List files in your directory and confirm your exported database dump is available.
Log in to your managed database.
Please verify the following parameters on your import command if the connection fails.
-h – Defines the Vultr database hostname. -P – Sets the port number for connecting to the database host. -u – Sets the Database user that should import the database. -p – Turns on password authentication for the user to access the database server.
Create a new database with the same name as your old database.
Exit the MySQL console.
Using the MySQL client, import the database to your managed database.
This rebuilds the database selected with the --database= flag.
When the database importation is complete, log in to your managed database.
Switch to the database.
Show tables and verify that all data exists.
Exit the console.
Log in to your local database server.
View all MySQL users.
Show the privileges granted to each user on the database. For example, dbuser.
Keep note of the privileges, or copy the listed GRANT statement in the output as below.
Exit the MySQL console.
Log in to your managed database.
Create all the database users.
When logged in to a Vultr Managed Database for MySQL, it's referred to as localhost.
Assign the user correct privileges to the database.
Refresh MySQL's privileges.
Exit the console.
You have migrated your local MySQL Database to a Vultr Managed Database for MySQL. Next, update the connection details in your applications to use the new database. Because you've created the same users and passwords in the new database, you should only need to change the database connection string to use the new managed database.
0 Comments
Be the first to comment and share your perspective with the community.