3

I'm trying to use PHP's exec() function to run mysqldump to back up a database named projectdata from Amazon Web Service. But I can only create an empty sql file.

I'm running the php file with xampp, under Windows 7 where mysqldump is in C:\xampp\mysql\mysqldump

exec('C:\xampp\mysql\bin\mysqldump --user=user --password=password --host=cannotTellyou.amazonaws.com:3306 projectdata  > backup.sql');
Community
  • 1
  • 1
  • you can able to post your [solution as a answer](http://stackoverflow.com/help/self-answer) and mark it as correct answer. – Mahendran Sakkarai May 29 '15 at 15:41
  • If you run MySQL on a non-standard port like 5555, mysqldump can take `--port=5555` as a switch. MySQL dump may have worked if you specified `--port=3306`. Not providing a port allows mysqldump to assume 3306 default port. – zedfoxus May 30 '15 at 03:50

3 Answers3

0

What you should do is: do a ssh login to your AWS machine. Run the mysqldump in command line and start debugging from there.

ssh <your remote AWS using your private_key>

then run

mysqldump -u <username> -p<password> yourDB | gzip > backupfilename.sql.tar.gz

use gzip if you want to zip your backup file, otherwise, it's not necessary.

Then refer to this post: how to mysqldump remote db from local machine

Community
  • 1
  • 1
Toby D
  • 1,465
  • 1
  • 19
  • 31
0

I would try to explicitly specify the file name instead of redirecting the output. Like this:

exec('C:\xampp\mysql\mysqldump --user=user --password=password --host=cannotTellyou.amazonaws.com:3306 projectdata -r backup.sql');

The -r option should be used also because:

Direct output to a given file. This option should be used in MSDOS, because it prevents new line '\n' from being converted to '\r\n' (carriage return + line feed).

MatteoSp
  • 2,940
  • 5
  • 28
  • 36
0

It works after removing the port number

C:\xampp\mysql\bin\mysqldump --user=user --password=password --host=cannotTellyou.amazonaws.com projectdata  > backup.sql