
In MySQL, you can backup your data either by using a logical or a physical backup. The former makes MySQL dump file. On the other hand, a physical MySQL backup is a raw copy of all files and directories containing the database information. You can create MySQL logical backups by using mysqldump or by installing automated tools such as automysqlbackup. In this guide, you'll create a physical MySQL backup.
Before you begin, ensure you have a non-root user with sudo privileges and a MySQL database server.
Log in to MySQL server with your root password.
The following SQL will reveal the data directory of your MySQL instance.
The output is similar to this.
Locate the MySQL data path without logging to the MySQL server.
The output is similar to this.
Stop the MySQL service.
Create a directory to store the MySQL file backup. Create a parent directory and sub-directories with the current date. This naming scheme allows you to determine the last backup date.
Copy the database file with cp.
Start the database server.
Stop the MySQL service.
Rename the current MySQL data directory. This step preserves a backup copy of the current state.
Create a new MySQL data directory.
Restore the MySQL backup.
Change the ownership of /var/lib/mysql to the mysql user.
Start the database server.
Test the backup by logging to the MySQL server as root.
Verify the database schema is correct.
Your databases are displayed. For example:
In this guide, you've created a physical backup of your MySQL database. This method is ideal for large databases and makes restoration easier when reinstalling a database server.
0 Comments
Be the first to comment and share your perspective with the community.