473,414 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

MySQL database backup

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 then it would
be possible to accidentally delete or overwrite large chunks of the data in
the database which presumably would then be lost. What is the usual
procedure for these situations?. Is it possible to back up a database
somehow so that data from a previous time can be retrieved?.

Ta,
Dave

Jul 17 '05 #1
4 2557
On 2005-04-13, Dave Moore <da**********@baesystems.com> wrote:
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 then it would
be possible to accidentally delete or overwrite large chunks of the data in
the database which presumably would then be lost. What is the usual
procedure for these situations?. Is it possible to back up a database
somehow so that data from a previous time can be retrieved?.


Of course. Read up on mysqldump.

--
Cheers
- Jacob Atzen
Jul 17 '05 #2
>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 then it would
be possible to accidentally delete or overwrite large chunks of the data in
the database which presumably would then be lost. What is the usual
procedure for these situations?. Is it possible to back up a database
somehow so that data from a previous time can be retrieved?.


mysqldump.

If you can access your MySQL database directly from a host you
control (e.g. your desktop), dump it to a file on your desktop.
You do need to install the MySQL client on that machine.
This option may not be available as hosts don't allow it or
you don't want your db accessable remotely.

If you can access your MySQL database from a shell account on
the hosting server, dump it to a file on the hosting server,
then FTP it somewhere else safe (if the hosting server loses
a hard drive, it might lose the master copy AND your backup
if you don't keep a copy elsewhere).

If you have to use PHP to access MySQL, invoke mysqldump from PHP
(exec()) and redirect the output to a file on the hosting server,
then FTP it somewhere else safe.

You restore stuff generated by mysqldump (which is a series of SQL
commands) by feeding the dump into the command line client called 'mysql',
e.g. for UNIX shells:
mysqldump -h host -u user -ppassword --databases db1 db2 ... > mysql.dump

mysql -h host -u user -ppassword db1 < mysql.dump

mysqldump has lots of options. Depending on your hosting situation,
you may want to back up all databases or just the one your host
assigns to you. Or maybe you want just specific tables. You can
back up just the schema (no data) or all of it. Some of the options
(like host name) may default properly in the right circumstances.

Gordon L. Burditt
Jul 17 '05 #3
Dave Moore wrote:
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 then it would
be possible to accidentally delete or overwrite large chunks of the data in
the database which presumably would then be lost. What is the usual
procedure for these situations?. Is it possible to back up a database
somehow so that data from a previous time can be retrieved?.

Ta,
Dave

I've been wondering about a closely related, or perhaps identical,
problem. How can I make a system of nightly backups where I can revert
to any previous nightly backup without gobbling up hard drive space
storing a file for each backup. Something like Subversion or CVS, except
for being more suitable for simple backups. Any products or methods out
there?

Pingveno
Jul 17 '05 #4
Dave Moore wrote:
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 then it
would be possible to accidentally delete or overwrite large chunks of the
data in the database which presumably would then be lost. What is the
usual procedure for these situations?. Is it possible to back up a
database somehow so that data from a previous time can be retrieved?.

Not a PHP question, not even a MySQL question.

Some people use stored procedures (mysql now supports stored procedures) to
try to isolate the DB from the application but at the end of the day it
doesn't really solve the problem - the only way PHP will be asing the
database to delete lots of stuff is because a combination of your PHP code
and the users request made it so. The real answer is to implement a proper
software engineering model (like CMMS) and write better code.

.....oh and don't forget to do backups.

C.
Jul 17 '05 #5

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, click and its done... The a restore option, that...
4
by: Neil | last post by:
Hi, I hope this question isn't too far off topic....I'm almost at my wits end trying to figure this out. I have a Mysql database and I wish to automate the backup of the database because I...
1
by: Konrad | last post by:
I have an internet portal based on MySql database and what I need is to make a database backup , after each actualization of data. I know how should PHP code look like but I have no idea how to...
4
by: news | last post by:
Our production database in an exported textfil runs about 60 MB. Compressed that's about 9 MB. I'm trying to import the export into another machine running FC3 and mySQL 11.18, and it appears as...
4
by: wzhao6898 | last post by:
Hi there, I'm trying to figure out if it's going painless to upgrade our oooold mysql 3.23 to the latest MySQL 4 or 5. Any suggestions? Thanks in advance! David
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.) And now... I just created new my database to new...
6
by: frank78 | last post by:
Hi everyone, I am having a little bit of trouble backing up some mySQL tables. I've been trying to adapt a script I found on the internet at...
2
by: GS | last post by:
Implemented web application using MySQL to maintain inventory of the office PC's/laptops/Routers/hubs and other stuff, here we are using MySQL as back-end Database on Linux Operating system. I need...
7
by: Randy | last post by:
Folks: We have a web-based app that's _really_ slowing down because multiple clients are writing their own private data into a single, central database. I guess the previous programmer did...
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 restore a database of two megabytes or less. My...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.