Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

dbf2mysql parameter, WWWXXXAPC, wwwxxxAPC, How to unsubscrube from dategen spam, docmd.close 2585, WWWXXXDOCO, nu vot, dhcpd lease file "binding state", WWWXXXDOCO, how to setup procmail to process html2text

Links

XODOX
Impressum

#1: How do I copy a table for backup and restore purposes

Posted on 2007-11-22 20:31:43 by Flemming

Hi there,

I have a small database running in mySQL on a web-hotel. I use PHP to access
the database.

Unfortunately, the web-hotel does not offer any possibilities for backing up
databases/tables, other than copying the tables manually one by one using
the facilities of phpMyAdmin.

What I would ideally like to have is a PHP routine that that makes an exact
copy of a specified table. I could then easily use that to createl copies of
all the relevant tables in the database.

I thought this would be a relatively easy task, but this does not appear to
be the case. Or maybe I am blind. I can see in phpMyAdmin the SQL statements
needed to create a new empty table and copy the content from the original
table. I could of course copy this code into PHP, but what then if I change
a table? Then I need to change this code as well.

Is there a smarter way?

Flemming

Report this message

#2: Re: How do I copy a table for backup and restore purposes

Posted on 2007-11-22 21:13:32 by Shion

Flemming wrote:

> I thought this would be a relatively easy task, but this does not appear
> to be the case. Or maybe I am blind. I can see in phpMyAdmin the SQL
> statements needed to create a new empty table and copy the content from
> the original table. I could of course copy this code into PHP, but what
> then if I change a table? Then I need to change this code as well.

You can try with the following SQL statement:

CREATE TABLE backuptable SELECT * FROM table_to_backup

You can use it easilly both from phpMyAdmin and from your custom made php script.

--

//Aho

Report this message

#3: Re: How do I copy a table for backup and restore purposes

Posted on 2007-11-22 22:21:27 by Flemming

> You can try with the following SQL statement:
>
> CREATE TABLE backuptable SELECT * FROM table_to_backup
>

Thank you for that suggestion. It works and creates a nice copy of all data
in a similar table.

However, it does not copy the index. Maybe there is an equally elegant way
to ensure that the index is copied as well? Or maybe I don't need it if I do
the restore by the following SQL statements:

TRUNCATE TABLE table_to_backup
INSERT INTO table_to_backup SELECT * FROM backuptable

Any suggestions as to whether this will work?

Regards

Flemming

Report this message

#4: Re: How do I copy a table for backup and restore purposes

Posted on 2007-11-23 11:30:37 by Captain Paralytic

On 22 Nov, 19:31, "Flemming" <flemm...@mail.dk> wrote:
> Hi there,
>
> I have a small database running in mySQL on a web-hotel. I use PHP to access
> the database.
>
> Unfortunately, the web-hotel does not offer any possibilities for backing up
> databases/tables, other than copying the tables manually one by one using
> the facilities of phpMyAdmin.
>
> What I would ideally like to have is a PHP routine that that makes an exact
> copy of a specified table. I could then easily use that to createl copies of
> all the relevant tables in the database.
>
> I thought this would be a relatively easy task, but this does not appear to
> be the case. Or maybe I am blind. I can see in phpMyAdmin the SQL statements
> needed to create a new empty table and copy the content from the original
> table. I could of course copy this code into PHP, but what then if I change
> a table? Then I need to change this code as well.
>
> Is there a smarter way?
>
> Flemming

phpmyadmin has an export tab in the database view. This will export
all the tables, complete with instructions to create the relevant
indexes

Report this message

#5: Re: How do I copy a table for backup and restore purposes

Posted on 2007-11-23 19:52:23 by unknown

Post removed (X-No-Archive: yes)

Report this message

#6: Re: How do I copy a table for backup and restore purposes

Posted on 2007-11-24 10:16:40 by Flemming

>>
>> Is there a smarter way?
>>
>> Flemming
>
> phpmyadmin has an export tab in the database view. This will export
> all the tables, complete with instructions to create the relevant
> indexes

Thank you for making we aware of the possibility in phpmyadmin to backup a
full database in one go. I missed that. It is certainly helpful to me, even
though it's not via PHP.

Flemming

Report this message

#7: Re: How do I copy a table for backup and restore purposes

Posted on 2007-11-24 10:21:06 by Flemming

>>Is there a smarter way?
>>
>>Flemming
>>
>
>
> I'd run a separate command to create your new table, then use
>
> SELECT * INTO NewTable FROM OldTable;
>
> Of course I'd do a regular backup of your entire database first, just for
> precautionary measures.
>
Thank you your reply.

Is there a way to create (an empty) NewTable in SQL with indexes and all
from OldTable?

Flemming

Report this message

#8: Re: How do I copy a table for backup and restore purposes

Posted on 2007-11-24 13:55:06 by Shion

Flemming wrote:
>>>
>>> Is there a smarter way?
>>>
>>> Flemming
>>
>> phpmyadmin has an export tab in the database view. This will export
>> all the tables, complete with instructions to create the relevant
>> indexes
>
> Thank you for making we aware of the possibility in phpmyadmin to backup
> a full database in one go. I missed that. It is certainly helpful to me,
> even though it's not via PHP.

You could download phpmyadmin and check the code they use to do it and then
you can write your own GPL code that uses the code from phpmyadmin.


--

//Aho

Report this message

#9: Re: How do I copy a table for backup and restore purposes

Posted on 2007-11-24 17:40:34 by Flemming

>>>>
>>>> Is there a smarter way?
>>>>
>>>> Flemming
>>>
>>> phpmyadmin has an export tab in the database view. This will export
>>> all the tables, complete with instructions to create the relevant
>>> indexes
>>
>> Thank you for making we aware of the possibility in phpmyadmin to backup
>> a full database in one go. I missed that. It is certainly helpful to me,
>> even though it's not via PHP.
>
> You could download phpmyadmin and check the code they use to do it and
> then
> you can write your own GPL code that uses the code from phpmyadmin.
>

Thank you for that suggestion. That must be the ultimate solution. However,
it would have been easier if someone could point at a CopyTable (using PHP
and mySQL) function somewhere out there on the web.

I'm still hoping for the ultimate tip.

Flemming

Report this message

#10: Re: How do I copy a table for backup and restore purposes

Posted on 2007-11-26 20:07:36 by unknown

Post removed (X-No-Archive: yes)

Report this message

#11: Re: How do I copy a table for backup and restore purposes

Posted on 2007-11-27 06:18:51 by Flemming

>>Is there a way to create (an empty) NewTable in SQL with indexes and all
>>from OldTable?
>>
>>Flemming
>>
>
> I usually create my own "config" files, that I use similar to restoring
> from a
> backup. As an example, I'll create a file named OldTable.sql that includes
> the
> SQL commands for creating the table and adding its indexes, and using a
> command
> like this to create the table...
>
> mysql -u username -p database_name < /path/to/OldTable.sql
>
> If I need to create a similar or duplicate table, I can copy that to a
> NewTable.sql file, and edit that with whatever changes I needed. Then add
> that
> one using..
>
> mysql -u username -p database_name < /path/to/NewTable.sql
>
> That way you can duplicate a table design a lot easier.
>
Thank you for another helpful suggestion. I'll keep that in mind and use it
in the future.

Flemming

Report this message