The following articles mainly describe how to back up MySQL database-putty in Linux, in addition, in the Linux operating system, MySQL database backup-putty's actual operations are worth our attention. The following is the detailed content of the article.
Abstract: This article introduces the Linux MySQL database backup-putty
Tags: Linux SQL database MySQL backup
Oracle helps you gain an accurate insight into each logistics Link
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 MySQL database backup file (equivalent to the database size) is generated in the current directory)
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:
MySQL database backup file
- Include "../config. php ";
- MySQL_CONNECT ($ dbhost, $ dbuser, $ dbpw) or die ("<H3> database inaccessible </H3> ");
- MySQL_SELECT_DB ($ dbname) or die ("<H3> database not established </H3> ");
- $ 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';
The above content is an introduction to the MySQL database backup-putty in Linux. I hope you will get something.