How to make Back Up and Restore from backup in MySQL Database.
In this tutorial i will show you easy ways to backup and restore the data in your MySQL database.
$ mysqldump -uroot -proot --databases ranger student erp > ranger_student_erp_backup.sql
Back up From the Command Line:
Here is the proper syntax to backup in command>
$ mysqldump --opt -u [uname] -p[pass] [dbname] > [backupfile.sql]
Here:
- [uname] Your database username
- [pass] The password for your database (note there is no space between -p and the password)
- [dbname] The name of your database
- [backupfile.sql] The filename for your database backup
- [--opt] The mysqldump option
For example, to backup a database named 'ranger' with the username 'root' and with password 'root' to a file ranger_backup.sql, using command:
$ mysqldump -uroot -proot ranger > ranger_backup.sql
Above command store your back file in home directory. If you want to backup in specific directory then go to your desired directory and execute the above command.
With mysqldump command you can specify certain tables of your database you want to backup.Each table name has to be separated by space.For example:
$ mysqldump -uroot -proot ranger commission content > ranger_backup.sql
Here>
- ranger is the databasename
- commission and content are table names separated by space.
$ mysqldump -uroot -proot --databases ranger student erp > ranger_student_erp_backup.sql
- ranger,student and erp are databases name separated by space.
$ mysqldump -uroot -proot --all-databases > alldb_backup.sql
Back up your MySQL Database with Compress:
If your mysql database is very big, you might want to compress the output of mysqldump. Just use the mysql backup command below and pipe the output to gzip.For example:
$ mysqldump -u [uname] -p[pass] [dbname] | gzip -9 > [backupfile.sql.gz]
Restoring your MySQL Database:
- Create an appropriately named database on the target machine
- Load the file using the mysql command:
Enjoy.........
Comments
Post a Comment