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:
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`;
update table:
update `nameoftable` set `created` = unix_timestamp( `created_at` ), `updated` = unix_timestamp( `updated_at` );
- remove older columns , rename newer ones
created_at
,updated_at
.
alternative way:
- set
datetime
columnsvarchar
field. update using query:
update `nameoftable` set `created_at` = unix_timestamp( `created_at` ), `updated_at` = unix_timestamp( `updated_at` );
- change columns
int
.
Comments
Post a Comment