LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-20-2006, 11:26 AM   #1
dolvmin
Member
 
Registered: Jul 2003
Location: Florida
Distribution: Red Hat 7.2/8/9, Fedora Core 1/2/3, Smoothwall, Mandrake 7.0/10, Vecter 4, Arch 0.6, EnGuarde
Posts: 289

Rep: Reputation: 30
MySQL Table Replicating question...


How do I copy a table from one db to another within the same MySQL server? Could I please have a command line answer. I'm creating a program that will need to do this in automation so that users who register to one forum can be automatically registered to several without needing to re-register. Thanks in advance...
 
Old 02-21-2006, 12:18 AM   #2
dolvmin
Member
 
Registered: Jul 2003
Location: Florida
Distribution: Red Hat 7.2/8/9, Fedora Core 1/2/3, Smoothwall, Mandrake 7.0/10, Vecter 4, Arch 0.6, EnGuarde
Posts: 289

Original Poster
Rep: Reputation: 30
I know this is a hard question, but is it really so hard that Linux Database Guruís don't have an answer for it?

I asked a tech for a suggestion that works at my job site. He laughed at me when I told him I had my MySQL on Linux. His expression was as if I was working on a kid's project. He told me I could have easily found the answer in the HELP for SQL on Microsoft. I kept my head up high and believed in what I had. Now I'm not feeling so proud. Not necessarily because no one answered here, but rather because the last (10?) questions I had resulted in 0 responses and the 0 response here seems to be stacking a larger number. 7 of them I managed to fix on my own. 2 of them were resolved by switching distributions. This is the 10th.

This community was a great place to seek for answers. But lately it has felt as if it was a place to destroy hope.
 
Old 02-21-2006, 01:05 AM   #3
MRMadhav
Member
 
Registered: Nov 2005
Location: Mauritius
Distribution: PCQLinux, SUSE Linux,Fedora Core 5, Fedora Core 6, Knoppix Live, Kubuntu Edgy, PCLinuxOS
Posts: 167

Rep: Reputation: 30
try this command in mysql but that does not recreate the keys though!

create table `newdatabase`.`newtablename` type=MyISAM select `field1`, `field2`,... from `originaldatabase`.`originaltable`
 
Old 02-21-2006, 01:35 AM   #4
dolvmin
Member
 
Registered: Jul 2003
Location: Florida
Distribution: Red Hat 7.2/8/9, Fedora Core 1/2/3, Smoothwall, Mandrake 7.0/10, Vecter 4, Arch 0.6, EnGuarde
Posts: 289

Original Poster
Rep: Reputation: 30
Smile

Problem with this line is if a table with the same name exist, it does not over write.

I did however find the answer for myself just now. Here's what I got (and this does work the way I want it too):
Code:
#! /bin/bash
# File created by Xenthorious on 02/21/2006
# This file copies table name smf_members and replaces the tables with the same name
# on all following databases.

# Obtain table information!
mysqldump -pPASSWORD -e web_main_forum_db smf_members > smf_members.dmp

# Replace installed table with the obtainee for database web_1_forum_db.
mysql -pPASSWORD -e'drop table smf_members;' web_1_forum_db
mysql -pPASSWORD web_1_forum_db < smf_members.dmp

# Replace installed table with the obtainee for database web_2_forum_db.
mysql -pPASSWORD -e'drop table smf_members;' web_2_forum_db
mysql -pPASSWORD web_2_forum_db < smf_members.dmp

# Replace installed table with the obtainee for database web_3_forum_db.
mysql -pPASSWORD -e'drop table smf_members;' web_3_forum_db
mysql -pPASSWORD web_3_forum_db < smf_members.dmp

# Remove table export for security reasons.
rm smf_members.dmp

#EOF
BTW, thank you very much for responding. It's nice to see that someone gave a damn.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL Table Replicating question... dolvmin Linux - Software 1 02-20-2006 11:28 AM
PHP/MySQL table question newuser455 Programming 10 11-03-2005 04:50 AM
MySQL non-realtime table-by-table mirroring Passive Linux - Software 1 01-20-2004 12:11 PM
How to import MS ACCESS Table including OLE filed into the MySQL Table ? myunicom Linux - General 1 11-28-2003 11:30 AM
deleted mysql table in mysql now cant do anything nakkaya Linux - Software 0 03-18-2003 06:03 PM


All times are GMT -5. The time now is 02:28 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration