Fri. Jan 21st, 2022

In the event you’ve by no means backed up your MySQL or MariaDB databases, now’s the time. Jack Wallen reveals you the right way to again up that information and restore it, in case your web site has met an premature demise.

database administrator working

Picture: iStock/GaudiLab

Your organization or private web site is operating like a champ. It serves your group and prospects, and your viewers and clientele develop day by day. That web site serves a vital service to you. Not solely is it a gateway to your organization, it in all probability permits your prospects to buy services.

SEE: 40+ open supply and Linux phrases it’s essential to know (TechRepublic Premium)

However sooner or later …

You hate to even give it some thought, do not you?

Someday one thing’s going to go unsuitable. When it does, you’d greatest hope you have got a backup. That backup should not solely embrace the recordsdata and configurations to your web site however the information housed within the database.

Meaning you want to have the ability to backup and restore your database. However how? I’ll present you.

What you may want

To make this work, you may want a web site that’s powered by both the MySQL or MariaDB database server. You may additionally want a person with sudo privileges. I’ll reveal with MySQL. In the event you’re utilizing MariaDB, you may want to regulate the way you log into the console ever so barely.

Prepared? Let’s go!

backup your database

That is so extremely straightforward, you will not consider it. 

First, let’s be sure that we all know what the title of the database is we’re seeking to backup. Log in to the MySQL server with the command:

sudo mysql -u root -p

As soon as within the console, checklist your databases with:


The above command will checklist each database you have got on the server. Make notice of the database you wish to again up and exit from the console with:


To again up that database difficulty the command:

sudo mysqldump DATABASE > DATBASE-backup.sql

The place DATABASE is the title of the database to be backed up.

And there you go, you have backed up your database.

arrange a day by day backup

Let’s use cron to create a backup that can run at 1 AM every single day. Open your crontab file for modifying with the command:

crontab -e

On the backside of that file, we’ll add the road:

00 01 * * * mysqldump -u root -p PASSWORD DATABASE > /dwelling/USER/DATBASE-backup.sql

The place:

  • PASSWORD is your MySQL root person password.
  • DATABASE is the database to be backed up.
  • USER is a username in your Linux system.

Save and shut the crontab file. Now, your MySQL database will likely be backed up every single day at 1 a.m. into the /dwelling/USER listing.

restore your database

OK, so for example catastrophe has struck, and it’s essential to restore your web site. You’ve got returned all of the recordsdata and configurations to their rightful place (due to a backup you created) and now it is time to restore the database from the backup. For this, you may difficulty the command (from inside the listing housing your .sql backup file):

sudo mysql DATABASE < DATABASE-backup.sql

The place DATABASE is the title of the database you backed up.

The restore command will take significantly longer than the backup command, so please be sure that to offer it time.

And that is all there may be to backing up and restoring a database to your web site. It is an extremely straightforward however essential process that you just hope you may by no means have to fret about. However simply since you hope that eventuality won’t ever come, doesn’t suggest you should not at all times be ready.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the most recent tech recommendation for enterprise professionals from Jack Wallen.

Additionally see

Source link

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *