473,386 Members | 1,706 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,386 software developers and data experts.

Using SELECT INTO to Backup a Database

I am trying to use the SQL "SELECT INTO" to create a copy of a MySQL
database.

My PHP code looks like this:

<?php

//Connect to server and database

include ("Connections/ovrs.inc");

if (isset($_POST['cmdBackup']))
{
$sql = "SELECT * INTO edenbackup FROM edenmaster";
$result = mysql_query($sql) or die
(ErrorCall(mysql_error(),"frmBackup.php","1"));

echo "The Backup is Complete";
}

?>

I get an SQL error when running this. If I change the SQL Statement to
be "SELECT * FROM edenmaster" it works fine, so I know the connection
is OK.

What is the correct syntax for "SELECT * INTO" for MySQL?

Thanks!

Jul 26 '06 #1
6 7193
no
On 26 Jul 2006 08:18:17 -0700, hi***********@yahoo.com wrote:
>I am trying to use the SQL "SELECT INTO" to create a copy of a MySQL
database.

My PHP code looks like this:

<?php

//Connect to server and database

include ("Connections/ovrs.inc");

if (isset($_POST['cmdBackup']))
{
$sql = "SELECT * INTO edenbackup FROM edenmaster";
$result = mysql_query($sql) or die
(ErrorCall(mysql_error(),"frmBackup.php","1"));

echo "The Backup is Complete";
}

?>

I get an SQL error when running this. If I change the SQL Statement to
be "SELECT * FROM edenmaster" it works fine, so I know the connection
is OK.

What is the correct syntax for "SELECT * INTO" for MySQL?
Not sure which version of MySQL you are running but see
http://dev.mysql.com/doc/refman/4.1/en/select.html

In particular: "The SELECT ... INTO OUTFILE 'file_name' form of SELECT
writes the selected rows to a file. The file is created on the server
host, so you must have the FILE privilege to use this syntax."

So, the argument specifies a file name, not another database AND you
need to have write permission on the server wherever you are going ot
put the file.

Chris R.
Jul 26 '06 #2
hi***********@yahoo.com wrote:
What is the correct syntax for "SELECT * INTO" for MySQL?
INSERT INTO edenbackup SELECT * FROM edenmaster;

The two tables would of course have to have the same field types in the
same order for this to work. Otherwise you would have to specify the
field names.

miguel
--
Photos from 40 countries on 5 continents: http://travel.u.nu
Latest photos: Malaysia; Thailand; Singapore; Spain; Morocco
Airports of the world: http://airport.u.nu
Jul 26 '06 #3
Thanks for the suggestions!

The reference I am using, "Sams Teach Yourself SQL", indicates that
SELECT * INTO can be used to copy one table to another:

"To copy the contents of a table into a brand new table (one that is
created on-the-fly) you can use the SELECT INTO statement."
>From what I have read here, that is not an accurate description for
MySQL.

Our goal is some PHP code that will create a copy (for backup purposes)
of a MySQL table residing on a production Linux server. We would like
to create the copy on the user's local machine. Is there a better way
to accomplish that?

Thanks!

Jul 26 '06 #4
hi***********@yahoo.com wrote:
>
Our goal is some PHP code that will create a copy (for backup purposes)
of a MySQL table residing on a production Linux server. We would like
to create the copy on the user's local machine. Is there a better way
to accomplish that?

Thanks!
I would use mysqldump instead. Run mysqldump and deliver the result as
a file download.

mysqldump reference:
<URL:http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html>

Jeremy
Jul 26 '06 #5
hi***********@yahoo.com wrote:
Thanks for the suggestions!

The reference I am using, "Sams Teach Yourself SQL", indicates that
SELECT * INTO can be used to copy one table to another:

"To copy the contents of a table into a brand new table (one that is
created on-the-fly) you can use the SELECT INTO statement."
>>From what I have read here, that is not an accurate description for
MySQL.

Our goal is some PHP code that will create a copy (for backup purposes)
of a MySQL table residing on a production Linux server. We would like
to create the copy on the user's local machine. Is there a better way
to accomplish that?

Thanks!
Different databases often have some differences in SQL implementation.
AFAIK, SELECT * INTO ... is not standard SQL, where as INSERT INTO xxx
SELECT... is.

You should always use manuals written for your particular database.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 26 '06 #6

hi***********@yahoo.com wrote:
Thanks for the suggestions!

The reference I am using, "Sams Teach Yourself SQL", indicates that
SELECT * INTO can be used to copy one table to another:

"To copy the contents of a table into a brand new table (one that is
created on-the-fly) you can use the SELECT INTO statement."
From what I have read here, that is not an accurate description for
MySQL.

Our goal is some PHP code that will create a copy (for backup purposes)
of a MySQL table residing on a production Linux server. We would like
to create the copy on the user's local machine. Is there a better way
to accomplish that?

Thanks!
I suggest using MySQL Backup, written in perl. It lets you backup on a
per-table per-database basis, archives, compresses, and emails them to
you, as well as rotates previous backups. Its very handy.

http://worldcommunity.com/opensource...ql_backup.html

Jul 27 '06 #7

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...
6
by: PG | last post by:
When deleting a row from the database, that id is now missing. So what I'm trying to do is update in a loop (maybe an sql loop if there is one) of all of the id numbers - sort of like renaming...
3
by: Thiko | last post by:
Hi I take one nightly full database backup at 02:00 and backup the transaction log to one backup set every 15mins. The commands to do this are as follows and are set up to run as database...
4
by: Nanchil | last post by:
Hi, We created a database (DB2 UDB 7.2 on solaris 8) without this (COLLATE USING IDENTITY ) option. But we need this now for binary sorting. The database is siebel database. Is it possible to drop...
6
by: Charles Morrall | last post by:
I have no experience with DB2 as such, but I've been tasked with configuring backup of a server running DB2 v8 on Windows Server 2003. I do have some experience with backups in general though. The...
5
by: jag | last post by:
hi, I am thinking about backup strategy. I have couple of questions for my db2 community brothers. 1. Can i use full online or offline database backup as base for incremental backup for...
2
by: R.A.M. | last post by:
Hello, I am learning SQL Server 2005. I would like to write a procedure making database backup using SMO. According to my book I should write such code: using...
7
by: Serge Rielau | last post by:
Hi all, Following Ian's passionate postings on problems with ALTOBJ and the alter table wizard in the control center I'll try to explain how to use ALTOBJ with this thread. I'm not going to get...
1
by: microsoft . public . sqlserver | last post by:
I am using SQL server 7.0. After restoring all the databses (Except distribution) Everything seems to be working fine except the backup maintenance plan. I put following detail in the maintenance...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.