Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How can I export MySQL database structure without disrupting results?
Old 02-26-2009, 08:22 AM How can I export MySQL database structure without disrupting results?
EdB
Skilled Talker

Posts: 79
Name: Ed Barnett
Trades: 0
Hi every.

I've got two copies of our company database (that we use for our website). It is MySQL and I have a 'laptop' copy and a 'live' copy. They structure of both is almost identical except for the following... I have;

1. Added Indexes to tables
2. Added columns to tables (that are allowed to be NULL)
3. Added Foreign keys

... to the 'laptop' copy. I don't want to effect ANY of the data in the 'live' copy as this is customer information/orders etc. I DO want the extra columns and indexes to be added in identical fashion to how they are on the 'laptop' version.

How can I export/import the structure of the database and all the foreign keys and indexes to my 'live' version without disrupting or deleting any of the data?
EdB is offline
Reply With Quote
View Public Profile Visit EdB's homepage!
 
 
Register now for full access!
Old 02-26-2009, 08:55 AM Re: How can I export MySQL database structure without disrupting results?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Simply by issuing "alter table" and "create index" commands on your productive DB.
http://dev.mysql.com/doc/refman/5.1/en/alter-table.html
http://dev.mysql.com/doc/refman/5.1/...ate-index.html

As for foreign key, as far as I know, you cannot declare them outside than the table create time.
For that, you would need to create a copy of the original table with a different name, and then issue
Code:
insert into newTable(
field1, field2, field3...
)
select 
  field1, field2, field3...
from oldTable
to transfer the datas and create the foreign keys.

But I don't see no way of doing this without offline time...
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-26-2009, 09:41 AM Re: How can I export MySQL database structure without disrupting results?
EdB
Skilled Talker

Posts: 79
Name: Ed Barnett
Trades: 0
Quote:
Originally Posted by tripy View Post
As for foreign key, as far as I know, you cannot declare them outside than the table create time....
Hi Tripy. Thanks for the quick reply. I created the foreign keys using phpmyadmin and didn't do them at the time of creating each table. On the structure page of the relevant table I went to the 'Relation view' link and added foreign keys there.

I forgot to mention that I'm using phpmyadmin - is there a quick way to do this? )
EdB is offline
Reply With Quote
View Public Profile Visit EdB's homepage!
 
Old 02-26-2009, 09:54 AM Re: How can I export MySQL database structure without disrupting results?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
is there a quick way to do this?
I never used it, but surely there must be a way to type your own queries...
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-26-2009, 10:03 AM Re: How can I export MySQL database structure without disrupting results?
EdB
Skilled Talker

Posts: 79
Name: Ed Barnett
Trades: 0
Quote:
Originally Posted by tripy View Post
I never used it, but surely there must be a way to type your own queries...
Yes there is, was just hoping for a quicker solution that typing numerous queries over and over. Never mind
EdB is offline
Reply With Quote
View Public Profile Visit EdB's homepage!
 
Old 02-26-2009, 10:23 AM Re: How can I export MySQL database structure without disrupting results?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
I honnestly don't know. I always have scripted my sql actions, never used a front-end.

I'm a dba, you see..
:-)
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-26-2009, 07:39 PM Re: How can I export MySQL database structure without disrupting results?
randon's Avatar
Experienced Talker

Posts: 46
Name: Brandon
Trades: 0
you could also export the contents of said table to a csv, edit the csv as you would like to see it in the new database then import the csv.

This would cause no downtime and would be a lot faster in terms of editing each column.

My website actually has a page for exporting MySQL tables to a csv. To import just use LOAD DATA.
__________________

Please login or register to view this content. Registration is FREE
Web development blog and scripts.
randon is offline
Reply With Quote
View Public Profile
 
Old 02-27-2009, 11:34 AM Re: How can I export MySQL database structure without disrupting results?
EdB
Skilled Talker

Posts: 79
Name: Ed Barnett
Trades: 0
Quote:
Originally Posted by randon View Post
you could also export the contents of said table to a csv, edit the csv as you would like to see it in the new database then import the csv.

This would cause no downtime and would be a lot faster in terms of editing each column.

My website actually has a page for exporting MySQL tables to a csv. To import just use LOAD DATA.
Hi Randon. Thanks for the info - in the end I spent half an hour last night doing the following;

I edited the mysql database connection include file (so no customers could edit data - forcing them to a 'Site Maintenance' page) and copied the data from the live database to my local one. Once that had all been copied correctly (a lot of errors were thrown up regarding the child values of foreign keys etc.) I then used DROP to delete the database online and imported the one from my laptop.

(I then edited the mysql include file so that customers could connect again).
EdB is offline
Reply With Quote
View Public Profile Visit EdB's homepage!
 
Reply     « Reply to How can I export MySQL database structure without disrupting results?
 

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.18775 seconds with 12 queries