Mysqldump in amazon using PHP - php

I want to have a database backup our database is hosted in amazon rds. My problem in everytime i run my PHP script it generates an sql file but it is empty.
Here is my code:
exec("/usr/bin/mysqldump -u *username* -p *password* | gzip > /var/www/html/db-backup/testdb.sql.gz");

I think that you need to specify which database you want to backup
exec("/usr/bin/mysqldump -u *username* -p*password* *dbname* | gzip > /var/www/html/db-backup/testdb.sql.gz");
and you have to specify password next to -p parameter without space (mysqldump -u youruser -pyourpassword -h yourhostname yourdatabase)

Related

How to get daily backup mysql database on godday hosting based on cronjob

i have issue to daily backup for mysql database.
export only all tables with data but not mysql function and stored procedure.
how to get full database backup?
I have use this cronjob.
mysqldump –opt -Q -h [myhost] -u myusername –p"*****" ebooklibrary > /fullpath.../_db_backups/openelibrary.sql
Add the "--routines" option, which is off by default in the query. This should give you the desired result. I hope this helps.
Read more here.
mysqldump --routines –opt -Q -h [myhost] -u myusername –p"*****" ebooklibrary > /fullpath.../_db_backups/openelibrary.sql

XAMPP (Windows) backup MySQL Database Automatically

I am trying to create a batch file in Windows to backup a MySQL Database, i have tried this:
C:\xampp\MySQL\bin\MySQLDump –u root –p database_name –result-file=”C:\Users\Administrator\Desktop\MySQLDump.sql”
but i get an error saying:
Got error: 1044: Access Denied for user ``#`localhost` to database `?u` when selecting the database
The solution to this problem/error was to use one of these mysqldump commands:
mysqldump --opt --lock-tables=false -u USER -p DBNAME > dump.sql
mysqldump --opt --single-transaction -u USER -p DBNAME > dump.sql
http://alvinalexander.com/mysql/mysql-error-1044-access-denied-for-user-using-lock-tables
Try this, it worked for me.
Don't forget to replace values inside {} as you need
C:\xampp\mysql\bin\mysqldump.exe -u{username} -p{passwrod} database > {/backuppath}.sql
Completed guide can be found at here:
https://www.tectut.com/2016/04/automatically-backup-mysql-databases-on-windows/

How to restore mysql from backup?

I have got alldatabase.sql file
How I can restore data with it?
My console comand is not working:
mysqldump -u root -p < alldatabase.sql
I must to create database first, but all database in my one file. What I must to do?
You use mysqldump to take a snapshot, but you restore using the mysql command
mysql -u root -p < alldatabase.sql

an alternative to mysqldump?

First of all, I am having serious problems with MYSQLDump, We have a dedicated server here for our main domain and I am running the following command:
mysqldump --opt -h localhost -u root -p ***** --all-databases > ~/var/www/vhosts/mydomain/httpdocs/db.sql
and I get nothing :(
But more importantly, I don't have root access to every server I have access to. But I do have database username and passwords. Surely there is a PHP only way of dumping the entire contents of a SQL database?
then why don't you use your user/password for the databases to do a per database dump as described i.e. here:
http://dev.mysql.com/doc/refman/5.1/de/mysqldump.html
mysqldump [options] --databases db_name1 [db_name2 db_name3...]
i just know two options to backup mysql-databases. One is to use mysqldump, the other one is to stop the mysql-server and backup the databasefiles. Doing dumps using PHP or whatever will last longer and cause much more trouble then just using mysqldump!
I was not aware there was a MySQL root.
Well, then that's the most likely cause of your problems, since you have this:
mysqldump --opt -h localhost -u root -p *****
^^^^^^^
The -u parameter expects a MySQL user and you are probably feeding it with systems' root user, which is something entirely different.
If you have a separate user for each database, I'm afraid you'll have to issue separate dumps.
Additionally, try to fetch error messages. You can redirect stderr to stdout by appending the 2>&1 operator to your command and you can grab output from shell_exec()'s return.
In the mysqldump command there is no space after -p and the password so your line should look like:
mysqldump --opt -h localhost -u root -p***** --all-databases > /var/www/vhosts/mydomain/httpdocs/db.sql

Empty files generated from running `mysqldump` using PHP

I keep getting empty files generated from running
$command = 'mysqldump --opt -h localhost -u username -p \'password\' dbname > \'backup 2009-04-15 09-57-13.sql\'';
command($command);
Anyone know what might be causing this? My password has strange characters in it, but works fine with connecting to the db.
I've ran exec($command, $return) and outputted the $return array and it is finding the command. I've also ran it with mysqldump > file.sql and the file contains
Usage: mysqldump [OPTIONS] database [tables]
OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help
So it would seem like the command is working.
Remove the space between -p and the password. If it didn't work, try to remove the quotes from the password
from MySQL documentation:
If you use the short option form (-p), you cannot have a space between the option and the password.
however, it is fine to have space with -h and -u options
I believe there are no spaces between -u and the actual username.
host: localhost user: peter password: pwd
would become:
-hlocalhost -upeter -ppwd
This is how I have done it - output is with maximum gzip compression:
<?php exec("/usr/bin/mysqldump --opt --host=MYSQLHOSTNAME --user=MYSQLUSER --password=PASSWORD DATABASENAME | gzip -v -9 >DATABASENAME.". date("Y-m-d_H-i-s") . ".sql.gz");?>
To put it in plain english, make sure to use the following options (all of them).
--user=USERNAME
--host=localhost
--password=****
The next non-option phrase should be your database name. If the command is followed by another non-option phrase, it will be treated as table names.
$command="mysqldump --xml --host=localhost --user=USERNAME --password=***** DBNAME > XMLTABLE.xml";
system($command);
$command = 'C:\xampp\mysql\bin\mysqldump --opt --user=root --host=localhost --password="password" my_db'.' > '.$backupdate.$sql_file_name; exec($command);
I faced the same issue and got it fixed by quoting the password. For example --password="yourpassword".
I had empty files too using mysqldump.
I run WampServer PHP7 under Windows 10.
system('mysqldump .... ') ;
Doen't work.
I had to add the full path (or add an Environment variable) :
system('C:\wamp64\bin\mysql\mysql5.7.9\bin\mysqldump.exe ...') ;
You have to specify full path to mysqldump:
// Linux:
$command = '/usr/bin/mysqldump --opt -h localhost -u username -p \'password\' dbname > \'backup 2009-04-15 09-57-13.sql\'';
// Windows:
$command = 'c:\mysql\bin\mysqldump --opt -h localhost -u username -p \'password\' dbname > \'backup 2009-04-15 09-57-13.sql\'';

Categories