We need to use the system’s scheduled task function to back up mysql in php. Next, I will introduce the method of backing up mysql in linux using php.
#Back up all backup files to the specified directory, such as /backup/mysql_data_backup
The code is as follows
代码如下 |
复制代码 |
mkdir /backup/mysql_data_backup -p
cd /backup/mysql_data_backup
wget /backmysql.txt -O backmysql.php
chmod +x backmysql.php
crontab -e
|
|
Copy code
|
代码如下 |
复制代码 |
0 13 * * * /usr/bin/php /backup/mysql_data_backup/backmysql.php
|
mkdir /backup/mysql_data_backup -p
cd /backup/mysql_data_backup
wget /backmysql.txt -O backmysql.php
chmod +x backmysql.php
crontab -e
代码如下 |
复制代码 |
#!/usr/bin/php
< ?php
//产生保存目录
$path = dirname(__FILE__) . '/' .date("Ym");
$filename = sprintf("%s/%s.sql.gz", $path, date("YmdHis"));
if(!is_dir($path))
mkdir($path);
//导出并压缩所有数据库
$cmd = sprintf("/usr/bin/mysqldump -uroot -ppassword --all-databases | /bin/gzip > %s", $filename);
echo "backuping...n";
`$cmd`;
echo "backup done.n"; |
Add a line of tasks
| means to execute the backup command using php at 0:13 every night
Note that this is only the planning information processing. If we want to execute the php file, we need to write one ourselves.
http://www.bkjia.com/PHPjc/630679.htmlwww.bkjia.comtrue
http: //www.bkjia.com/PHPjc/630679.htmlphp backup mysql we need to use the system's scheduled task function, let me introduce the example of php backup mysql in linux method. #Back up all backup files to the specified directory, such as /backup/...