473,785 Members | 3,285 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ("Connection s/ovrs.inc");

if (isset($_POST['cmdBackup']))
{
$sql = "SELECT * INTO edenbackup FROM edenmaster";
$result = mysql_query($sq l) or die
(ErrorCall(mysq l_error(),"frmB ackup.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 7205
no
On 26 Jul 2006 08:18:17 -0700, hi***********@y ahoo.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 ("Connection s/ovrs.inc");

if (isset($_POST['cmdBackup']))
{
$sql = "SELECT * INTO edenbackup FROM edenmaster";
$result = mysql_query($sq l) or die
(ErrorCall(mys ql_error(),"frm Backup.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***********@y ahoo.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***********@y ahoo.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***********@y ahoo.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*******@attgl obal.net
=============== ===
Jul 26 '06 #6

hi***********@y ahoo.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
15465
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 shows all current backups, and restores the selected one with one click...
6
4040
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 them. It did partly work because all the id's were set to 22. Thats because there was 22 rows. Here's the code I used: $result = mysql_query ("SELECT * FROM counter"); for($counting = 1; $row = mysql_fetch_row ($result); ++$counting)
3
7576
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 jobs: -- Database Backup BACKUP DATABASE TO WITH NOINIT ,
4
7719
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 and recreate the database with COLLATE USING IDENTITY option and restore the database. Please advise. Nanchil.
6
5198
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 backup software I'll be using is Backup Exec 10, but Backup Exec doesn't have a specific agent for DB2, as it does for SQL and Oracle. The supplier of Backup Exec claims I can use the Open File option of Backup Exec to backup DB2. I find this a...
5
2309
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 tablespace? For example, if i take backup of database A which contain tablespace X1,X2, can i take full offline or online backup of A and then take incremental backup of X1,X2?
2
4348
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 Microsoft.SqlServer.Management.SMO; public static void MakeBackup() { Server server = new Server("localhost"); Backup backup = new Backup();
7
6992
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 into the GUI because it is hard to describe in text. First of all what is the purpose of ALTOBJ()? This procedure was created mostly for ISVs who need to do produce change scripts to upgrade application from release to release, but it can also
1
3638
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 plan "General Tab: Plan Name --- DB Maintenance Plan1 () All Databases Optimizations tab:
0
9643
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10315
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9947
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.