php - Bulk convert and update datetime column values to UNIX timestamp? -


background

i have mysql db around 16 million records. there 2 columns created_at , updated_at presently in datetime format.

the problem

i'd change unix timestamp converting values , updating records new values.

i know how php in loops, there way perform update executing single query in mysql?

as it'll 1 time change; can proceed way:

  1. create new columns int datatypes , name them, say, created , updated.

    alter table `nameoftable`     add column `created` int unsigned not null default '0' after `created_at`,     add column `updated` int unsigned not null default '0' after `updated_at`; 
  2. update table:

    update `nameoftable` set `created` = unix_timestamp( `created_at` ),     `updated` = unix_timestamp( `updated_at` ); 
  3. remove older columns , rename newer ones created_at , updated_at.

alternative way:

  1. set datetime columns varchar field.
  2. update using query:

    update `nameoftable` set `created_at` = unix_timestamp( `created_at` ),     `updated_at` = unix_timestamp( `updated_at` ); 
  3. change columns int.

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -