Question

I want to export a single table into an SQL file for backup every day using cron-job.
I've looked around for some scripts bust most were not so user-friendly.

I've seen this: http://help.1and1.com/hosting-c37630/linux-c85098/php-c37728/importing-and-exporting-mysql-databases-using-php-a595887.html

But it exports the whole DB (which weighs about 10GBs), I need to export a single 16mb table.

The preferred method is for it to look like a normal sql file (like the ones Phpmyadmin exports), something like this:

 CREATE TABLE IF NOT EXISTS `parts` (
  `flag` char(1) NOT NULL DEFAULT '',
  `comp` int(10) NOT NULL DEFAULT '0',
  `name` varchar(255) NOT NULL DEFAULT '',
  `rname` varchar(255) NOT NULL DEFAULT '',
  `hname` varchar(255) NOT NULL DEFAULT '',
Était-ce utile?

La solution

You can just change this script and add params for tables name

For example change string

$command='mysqldump --opt -h' .$mysqlHostName .' -u' .$mysqlUserName .' -p' .$mysqlPassword .' ' .$mysqlDatabaseName .' > ~/' .$mysqlExportPath;

to

$command='mysqldump --opt -h' .$mysqlHostName .' -u' .$mysqlUserName .' -p' .$mysqlPassword .' ' .$mysqlDatabaseName .' parts > ~/' .$mysqlExportPath;

Where parts is your table name

Autres conseils

http://www.tutorialspoint.com/mysql/mysql-database-export.htm

You could either make a bash script, or you could use the exec() php function.

<?php

exec('mysqldump -u XXXX -p XXXX [table_name] > [output file]')
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top