How to Backup and Restore MySql Database Files | MySql Tutorial

Submitted by techyboy on Fri, 10/13/2017 - 09:21
backup and restore mysql database

MySql is the mostly used database in all server environments. Though the latest mysql version is 7.x, most websites still use mysql 5.6 to make it compatible with various php-plugins and CMS packages like Drupal, Joomla and Wordpress etc. It is necessary to regularly dump all database tables so that you can store the backup files in some where in the same computer or other PC. Skipping database backups puts you under risk of loosing your latest data say new articles added to your website if restored with an old backup file.

In small, medium and big companies, employees like database admins take regular backups. If you are a website owner, you may not have staff to do it regularly. So it is mandatory for small website owners to learn basics of backing up of MYSQL database tables. Here we refer to dumping as backup process. you can use username and password command we have shown at last directly form linux commandline. If you are using Ubuntu, Centos or any other OS, just use the last command without logging into mysql to get a mysql dump file.

MYSQL Dump Commands

shell> mysqldump dbname > targetfile.sql

shell> mysqldump --dbname1 dbname2 > singletargetfile.sql

shell> mysqldump --all-databases > alldbsinglefile.sql

shell> mysqldump -u root -p dbname > targetfile.sql


If your website or webapp is malfunctioning due to virus, cross-site scripting, accidental deletion of articles or posts for any reason, you need to restore your mysql database to retain all the data. Even if you are moving out of one hosting provider to other, you need to import your mysql data into the new server. Though you can approach Freelancers to do this website or server migration process, it is not always good without proper knowledge about how to maintain mysql databases. So learn the basics of importing mysql dump file we dumped earlier into database.


MYSQL Import / Restore Commands

shell> mysql database_name < database_name.sql

shell> mysql --one-database database_name < all_databases.sql

shell> mysql -u root -p database_name < database_name.sql


Do not forget to drop comments if this post helps you.


Add new comment

Related Content