MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old April 4th, 2000, 09:12 AM
richieb richieb is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 1999
Location: Stockton, Cleveland, England
Posts: 3 richieb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi,

Anyone know a quick way of inserting rows from one table into another table with the same column names and types?

I have created the second table.

As I didn't know how to do this I used to export the rows to a file using redirection from the command line, then remove the headers from the exported file, then load data infile it from MySql into the new table.

This used to work ok, however I now have over 1,000,000 rows that I need to port across and I keep getting out of memory errors and nearly crash my webserver.

All I want to do is something similar to :

insert into table2 values (select * from table1 where criteria)

very rough SQL I know, but something similar to that.

I have scanned the MySQL manual but it only seems to have insert into and then filenames.

Hope someone can help, probably something dead simple that I have not picked up ;o)

TIA,

Regards,

RichieB

Reply With Quote
  #2  
Old April 4th, 2000, 12:07 PM
donarb donarb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 1999
Location: Seattle
Posts: 133 donarb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
MySQL has an INSERT ... SELECT syntax. Remove VALUES and put SELECT in its place.

Don

Reply With Quote
  #3  
Old April 4th, 2000, 03:51 PM
richieb richieb is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 1999
Location: Stockton, Cleveland, England
Posts: 3 richieb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for the info, I knew it would be simple.

However that command seemed to crash our server, whoops. Too many open files caused the crash ???????

I have contacted our support team to see why exporting from one table to another should cause the server to crash.

I know it is over 1,000,000 rows but surely it should be okay.

Anyone have any similar problems like this?

Once I get these 1,000,000+ rows archived I can delete them from the live DB. I guess I will have to archive daily or weekly at the least. I suppose I could set up a cron job to do it for me.

Cheers,

RichieB

Reply With Quote
  #4  
Old April 13th, 2000, 04:38 PM
Bill Patterson Bill Patterson is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Posts: 6 Bill Patterson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Have you tried doing your load directly rather than as an insert? Either at the command line or through a shell script you may instruct MySQL to load a tab-delimited file.

The command line would be:
mysql -u [account name] -p -B <load.sql

and load.sql would be:
use [databasename];
load data infile '[fully qualified file name]' into table exampletable;

Bill

Reply With Quote
  #5  
Old April 14th, 2000, 03:02 AM
richieb richieb is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 1999
Location: Stockton, Cleveland, England
Posts: 3 richieb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi Bill,

Thx for the reply.

The problem is in getting the data out of a table into another, we cannot seem to get it out of the table either into another table or into a file without bringing the web server down.

We have resorted to a MySQLDump and stripped out all of the inserts that we want and then we have edited the file and search/replaced the table name with our new table name. I have now deleted the 1,000,000+ rows but as it is a log table it has already grown to over 500,000 again. I really like logging page views to the DB because we get instant control over full page views and exact pages unlike the apache server logs that need analysis tools.

Should MySQL be able to handle tables efficiently with over 1,000,000 rows. The table in question has an index and 10 fields, we have no problem inserting into this table and no problem selecting from this table if the where clause uses the index. However if we try to query it using a where clause that is not indexed it goes away for about 10 minutes (at which point our site dies) and then returns the results.

Any help???

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Inserting into one table directly from another


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway