1

I'm trying to dump some of my tables if the prefix of theme is matching a given sub string using php. Trying to use php's system did not bring any result in sense the dump file was not created. I thought to use the command line function exec to achieve my result and I was making the following

 exec('E:/xampp/mysql/bin/mysqldump '. $dbname .' -h '. $this->host .' -u ' .$this->user . ' $(E:/xampp/mysql/bin/mysql -u '. $this->user . ' -p ' . $dbname .' -Bse "show tables like \'wp_dev%\'")> mydb.sql 2>&1', $output);

but to sub query what would filter out the matching tables is returning the following error

mysqldump: unknown option '-s'

It seems like I'm missing something by the syntax.

0

1 Answer 1

2

Use like this, it will take dump of only listed tables.

exec('E:/xampp/mysql/bin/mysqldump -h '. $this->host .' -u ' .$this->user . ' -p'. $this->password .' '. $dbname .' table1 table2  > /path_to_file/dump_file.sql');
Sign up to request clarification or add additional context in comments.

3 Comments

and how could I build in this query "show tables like \'wp_dev%\'" I would like to dump just the matching tables
for that I was making something like $tables ="SHOW TABLES FROM $dbname LIKE 'wp_%'"; $result = mysql_query($tables); $to_dump = array(); while ($dumped_tables = mysql_fetch_row($result)) { $to_dump[] = $dumped_tables[0]; } and trying to use implode. But something I'm missing by mysqldump
check my updated solution, you have to pass tables name which you want to take backup of, you can use implode(' ', $to_dump); to form string of table names.

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.