1

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 '',

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

1

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]')

2 Comments

I'm guessing "u" is for user and "p" is for password, but shouldn't there be a place to insert the DB itself?
Yep -u [username] -p [password] and could prepend the table_name with the db for example database_here.table_name_here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.