Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting table index from Int to Bigint MySQL

Tags:

mysql

I've been running a small web-based experiemnt using Facebook UIDs to verify unique users.

Recently I've discovered that UIDs can be bigger than I realised among some users, so my int-based system is now inadequate and I need to convert to bigint.

I can't risk losing the results I already have, but need to convert the table so that the index containing the uid is now bigint. Are there any particular issues changing the type of an index column, and would it be as simple as:

ALTER TABLE breadusers MODIFY userid bigint;

?

like image 481
Hal Clive Avatar asked Mar 20 '11 16:03

Hal Clive


1 Answers

In theory this should be absolutely fine, although it the data really matters, I presume you have a recent backup anyway in case something goes awry.

That said, I'd probably be tempted to store the Facebook UID as a string (i.e.: in a VARCHAR field) and simply have a generic auto-incremented ID field. Then again, that's an answer to a different question. :-)

like image 139
John Parker Avatar answered Sep 21 '22 03:09

John Parker