Backup of mysql database in Linux-putty

Source: Internet
Author: User
Prerequisites: if you have the ssh logon permission, follow these steps: download the software putty and set the ssh logon option to log on to your home page. * (access via ftp) run the mysqldump command to execute database backup, the mysqlrestore command restores the database. Format: pXXXXXXX @ kundenserver :~ Mysqldump-hdbXX.puretec.de-

Prerequisites: if you have the ssh logon permission, follow these steps: download the software putty and set the ssh logon option to log on to your home page. * (access via ftp) run the mysqldump command to execute database backup, the mysqlrestore command restores the database. Format: pXXXXXXX @ kundenserver :~ Mysqldump -hdbXX.puretec.de-

Prerequisites: You have the ssh logon permission.

Work steps:

  • Download the software putty and set the ssh Login Option
  • After logging in, go to your home page Directory * (accessible through ftp)
  • Execute the mysqldump command to execute database backup, and the mysqlrestore command to restore the database.

Format:


PXXXXXXX @ kundenserver :~ > Mysqldump -hdbXX.puretec.de-upXXXXXXX-p ******** dbXXXXXXX> dbXXXXXXXX. SQL


PXXXXXXX @ kundenserver :~ > Mysql -hdbXX.puretec.de-upXXXXXXX-p ********* dbXXXXXXX <dbXXXXXXXX. SQL


  • After mysqldump is executed, a backup file is generated in the current directory (the size is the same as the database size)
  • You can download the backup database file package through ftp.
  • Restoring the database is opposite to the above two

You can also write a php script to complete the above operations:


Backup File

Include "../config. php ";
MYSQL_CONNECT ($ dbhost, $ dbuser, $ dbpw) or die ("unable to access database ");
MYSQL_SELECT_DB ($ dbname) or die ("the database has not been created ");
$ Path = getenv ('document _ root'). "/DB_backup ";
$ Result = MYSQL_QUERY ("show tables ");
$ Numrow = MYSQL_NUM_ROWS ($ result );
For ($ I = 0; $ I <$ numrow; $ I ++ ){
$ Table = MYSQL_RESULT ($ result, $ I );
Echo "$ table ...";
System (sprintf ("mysqldump -- opt-h $ dbhost-u $ dbuser-p $ dbpw $ dbname $ table | gzip> % s/$table. SQL .gz", $ path ));
Echo "DONE \ n ";
}
MYSQL_CLOSE ();

Restore Files

Include "../config. php ";
System (sprintf (
'Gunzip-c % s/dump. SQL .gz | mysql-h % s-u % s-p % s % s ',
Getenv ('document _ root '),
$ Dbhost,
$ Dbuser,
$ Dbpw,
$ Dbname
));
Echo '+ done ';

498) this. width = 498; 'onmousewheel = 'javascript: return big (this) 'alt = Attachment src = "/files/uploadimg/20051017/1734100 .jpg" border = 0>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.