Jump to content

Compare 2 MYSQL Tables


gevensen
Go to solution Solved by mac_gyver,

Recommended Posts

Is there an easy way to compare the structure ( not data ) to see if 2 tables are identical?

 

Ive used describe but im at the point where i have to loop thru the structure of each table

 

I have a project with mutiple databases and tables and the tables in each db need to be identical

 

I can create identical tables but im having an issue figuring out an easier way to simple compare 2 table structure

Link to comment
Share on other sites

Ive been working on this project for a few years its 117 tables per DB and about 10 DBs

In development ive made changes to some of the tables

The script i created a while back was missing an update here and there or i was forgetting

Ive fixed that now I need to check the tables

the array_diff was good

what i did was compare the arrays from describe in both tables

if(count(array_diff($a,$b)>'0') was greater than zero there's some kind of difference

I don't care what difference at that point i take a sql dump of table b, rename table b in case of failure to xb, recreate table b from the structure of table a, import the sql dump and if all is well delete xb

I had seen array_diff before but didnt think about taking a count of the arrays returned, where if it was greater than zero i had a problem

just ran it on wamp and that seems to do the trick

thanks mac_gyver for the thought

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.