-1

How do I export all tables in a MySQL database to a .sql file and save the file to the path I specified using PHP? I want to write a program with the functions above and execute it regularly.

Pang
  • 9,564
  • 146
  • 81
  • 122
HSC
  • 1
  • 1
  • Before posting a question, you should have done the proper research and made attempts to solve your issue yourself. Then, if you get stuck on something _specific_, come back and show us your attempt. Please read [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users), [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) and also [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) – M. Eriksson Nov 21 '18 at 06:01
  • 2
    I literally goggled your title and this was the 1st result on page. Looks like it should get you going in the right direction. https://stackoverflow.com/questions/22195493/export-mysql-database-using-php-only – Joseph_J Nov 21 '18 at 06:05
  • Possible duplicate of [Export MySQL database using PHP only](https://stackoverflow.com/questions/22195493/export-mysql-database-using-php-only) – Ori Marko Nov 21 '18 at 06:47
  • I've tried the method provided by the URL (https://stackoverflow.com/questions/22195493/export-mysql-database-using-php-only). Got a fatal error: "allowed memory size of xxx bytes" and the method does not seem to provide a way to specify a path to save the file. – HSC Nov 21 '18 at 07:01

1 Answers1

0

execute the MySQL query with PHP

mysql -e "select * from myTable" -u myuser -pxxxxxxxx mydatabase > mydumpfile.txt
Justin J
  • 808
  • 8
  • 14