472,334 Members | 2,469 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,334 software developers and data experts.

Backup with mysqldump

I use Windows XP and Apache.

I am trying to backup a database on my local computer with the
following php code:

$dbname = 'ol';
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$backupFile = $dbname .'-' .date("Y-m-d-H-i-s") . '.sql';
$command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname >
$backupFile";
if (!system($command, $retval)){die('Backup failed.);}

It does produce a file like C:\Program Files\xampp\htdocs
\onlinelearning\ol-2007-06-20-13-31-09.sql, but it is empty.

mysqldump.exe is at C:\Program Files\xampp\mysql\bin\mysqldump.exe and
the script is sitting in the folder C:\Program Files\xampp\htdocs
\onlinelearning.

When I put a copy of mysqldump.exe in the folder C:\Program Files\xampp
\htdocs\onlinelearning I get a black sreen saying 'Enter password:'.
When I give the password I get a file like this:

-- MySQL dump 10.10
--
-- Host: localhost Database: ol
-- ------------------------------------------------------
-- Server version 5.0.18

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS,
FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE,
SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

---

Any help is greatly appreciated.

Regards,

Jan Nordgreen

Jun 20 '07 #1
7 4598
I got it to work by changing "-p $dbpass" to "--password=$dbpass"!

This works:

$dbname = 'ol';
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$backupFile = $dbname .'-' .date("Y-m-d-H-i-s") . '.sql';
$command = "mysqldump --opt -h $dbhost -u $dbuser --password=$dbpass
$dbname $backupFile";
$dummy = system($command, $retval);
die($retval);

What remains is not to be dependent on mysqldump.exe in the script's
folder.

Regards,

Jan Nordgreen
Jun 20 '07 #2
This did it: $command = "..\..\mysql\bin\mysqldump ...

Final question in this conversation with myself :), why didn't php
find mysqldump.exe on its own. Do I set this in php.ini?

Regards,

Jan Nordgreen

Jun 20 '07 #3
damezumari wrote:
$command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname >
$backupFile";
Any help is greatly appreciated.
You should read the mysqldump manual more carefully.

--password[=password], -p[password]
The password to use when connecting to the server. If you use the short
option form (-p), you cannot have a space between the option and the
password. If you omit the password value following the --password or -p
option on the command line, you are prompted for one.
Jun 20 '07 #4
On Jun 20, 7:58 pm, damezumari <jannordgr...@gmail.comwrote:
This did it: $command = "..\..\mysql\bin\mysqldump ...

Final question in this conversation with myself :), why didn't php
find mysqldump.exe on its own. Do I set this in php.ini?

Regards,

Jan Nordgreen
it has to be in the path, use the system properties window, advanced
environmental vars, to set the system path to include the path to
executables you wish apache to be able to use.
It does sound though like you have your apache being run as SYSTEM -
and so it is able to range throughout the filesystem, you might
consider locking that down a bit (if you are running xp pro) but
creating and apache user.
Also when backing up your database you dont need root permissions,
create a user which has only the right to select and lock tables for
that database, and use that to backup, then should your script leak
out, they can read but not change your database. Each database could
have a "web user" which ahs only the rights your app needs it to have
a "backup user";select, lock tables, and of course there may well be a
root account with a password (which is not the default) which is used
to administer the whols DBMS.
my $0.02 (it doesnt take much to get into the habit of this, consider
where a backup user password will be, scripts marked db_backup and
cron jobs - which might result in password being sent via email, so
its best to have users specific for the task they will perform IMHO.

Jun 20 '07 #5
Anonymous:
Thanks for the tips on the extra space. You were right.

shimmyshack:
1. I did as you suggested in Control Panel and edit the system
variable Path to include the folder where mysqldump.exe sits. Then I
could replace "..\..\mysql\bin\mysqldump..." with "mysqldump...".

2. " It does sound though like you have your apache being run as
SYSTEM -
and so it is able to range throughout the filesystem, you might
consider locking that down a bit (if you are running xp pro) but
creating and apache user."
How do I create an apache user?

3. I created a backup user like you suggested and it worked fine!

Thank you for your help!

Regards,

Jan Nordgreen

Jun 21 '07 #6
On Jun 21, 4:19 pm, damezumari <jannordgr...@gmail.comwrote:
Anonymous:
Thanks for the tips on the extra space. You were right.

shimmyshack:
1. I did as you suggested in Control Panel and edit the system
variable Path to include the folder where mysqldump.exe sits. Then I
could replace "..\..\mysql\bin\mysqldump..." with "mysqldump...".

2. " It does sound though like you have your apache being run as
SYSTEM -
and so it is able to range throughout the filesystem, you might
consider locking that down a bit (if you are running xp pro) but
creating and apache user."
How do I create an apache user?

3. I created a backup user like you suggested and it worked fine!

Thank you for your help!

Regards,

Jan Nordgreen
if you have windows xp PRO, you can goto "my computer" (or explorer)
tools->folder options->view->uncheck "use simple file sharing
(recommended)"
now you will have more config options to create users.
start->run->compmgmt.msc->local users and groups->users
(right click users on left) -new user
username:apache
full name: apache user
description: this is the user apache uses
set some strong password
[] user must change password at next logon
[x] user cannot change password
[x] password never expires
[] account is disabled
ok it
double click your new apache user, member of tab
get rid of everything, so it is a member of nothing.

now you have your apache user, find the folders which you would like
apache to be able to access
each one - think where your config files are, the exes, the tmp
folder, the doc root, everything that apache needs to function, if you
run php as a module then include where php is.
You might find that all this is covered by something like
c:\xampp\
because everything lives under there, otherwise you will have to do
each manually, these days your config should not be in c:\windows or c:
\windows\system32 if it is move it out of there and next to the apache
executable or somewhere less "important"
right click that folder and select
protperites->security tab
add->advanced->find
find your apache user, click on it and say ok, and ok it again
once you have your apache user added, you will need to set its rights
useing the checkboxes.
the apache user will need write access to some parts but read only on
others, think carefully and make your decisions.
now that you have everything set up goto
start->run->services.msc
double click the apache service (I am assuming you have apache running
aas a service)
logo on tab
under "this account" type the user "apache" and its strong password,
apply, and ok the warning, restart the service
apache will start if it has enough rights to do so.
Now if php is running as a module, write a short script that tries to
read files from outside the folders for which apache has permission.
It shouldnt be able to.
Same goes for write permissions.
try to start a session with php, it will use the tmp directory and you
should check it can read/write to the session files.
If everything is ok, you now have a more secure setup.
hope it helps.

Jun 21 '07 #7
Thanks for the answer!

Unfortunately I have only Windows XP Home, but the day i upgrade to
Pro I will use your notes.

Regards,

Jan Nordgreen

Jun 21 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: James | last post by:
HI, I'm looking for a script that will allow users/admins to have a one click backup solution for a MYSQL Database.. 'BACK DATABASE' button,...
4
by: Dave Moore | last post by:
Hi All, I'm looking at using PHP and MySQL for a particular website application. However, I was a bit concerned that if a PHP script went wrong...
0
by: xabaras | last post by:
Doubt. Backup of the database. Example: CREATE DATABASE prova; CREATE TABLE `test` (`progressivo` tinyint(3) unsigned NOT NULL...
1
by: Thiko | last post by:
Hi We currently use mysqldump to dump all our db's in quick mode to one file, backup.sql. This file has come quite large. mysqldump -Aq -u...
3
by: Reuben Pearse | last post by:
Hi all, I've just converted the tables in a big database (approx 27 million records) from MyISAM to InnoDB. When I was using MyISAM I backed up...
2
by: Raffi | last post by:
I use the --all-databases switch to backup my entire database. Sometimes there's a need to restore individual databases or tables form the backup...
0
by: newman | last post by:
Dear all, I have mysql 4.1.11 on my current server, i need my database restore another server.. (another server mysql version is 4.1.11 same.) ...
4
by: Bootstrap Bill | last post by:
I'm looking for a PHP program to backup and restore a mysql database. I'm using Godaddy to host a forum. Their mysql control panel will only...
15
by: Jerry Yang | last post by:
Hi I'm having issues with mysqldump so need to create backups of my mysql databases using PHP. Can any one recommend a way to do this with out...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.