Posts Tagged ‘sync mysql’

Synchronise database field columns in mysql

Share on TwitterShare on TumblrSubmit to StumbleUponSave on DeliciousDigg ThisSubmit to redditShare on MyspaceShare via email

This post is useful if you are having a similar issue , which in my case was like this

I was importing a drupal database, using node_import , and importing tables that way will double md5 passwords fields.

On the old database, the passwords are already md5′d .
Drupal login will md5 it.

So two solutions can occur to mind,

1: disable md5′ing from login system (user’s module)

2: keep original login system and sync database 1 time, and problem is solved.

Here is the short method to do so….

First, i took out the old table with users and md5′d passwords from the database 1.

Opened a new table, inserted the values in .

(this step is needed just to simplify the update command without connecting to other database especially if they are not on same localhost as it was in my case)

Step two, consider fields to sync.

T1: has  username, password, etc
T2: has user, pass, etc

So we  want to update the pwd on table T2 to have the password from T1 based on the username (there must be an identified or common field to use ofcourse)

The table 2 i had was called enusers and the old one was called users.

From phpmyadmin or any mysql command line :

UPDATE enusers set enusers.pass =  (select users.password from users where users.username = enusers.user)

Problem solved,

Password are updated with the old md5′d passwords from past table and tables synced.

nb: Do this step after using the node_import as you would do usually, for more information about node_import click here

Share on TwitterShare on TumblrSubmit to StumbleUponSave on DeliciousDigg ThisSubmit to redditShare on MyspaceShare via email