MySQL tables for continent names, country names and their ISO-3166 codes

Map of the world Here is a MySQL table containing continent names, country names and their ISO-3166 codes.

Needed one a while ago, but the ones I found were either kind of lacking or kind of old. So I made one myself by converting a datafile on Wikipedia into the format I wanted. Used some regular expressions and manual corrections. Later I also went through newsletters with Updates on ISO 3166. Hopefully I got it all right, and hopefully it can save you and others some time as well.

I have also subscribed to their updates and try to follow up when they change anything.

If you find any mistakes or updates I’ve missed, please let me know 🙂

The data

Created a project on BitBucket for some change tracking. The latest version of the SQL script is found at and it’s embedded below 🙂

  • Amir

    Cool! just what I needed, just when I needed it! 10x!

  • David

    Very nice! I was about to compile this list myself and then found your site. Thank you so much for saving me all that work 🙂

    • Glad it could help someone else! Please let me know if you notice anything that should be updated or something like that.

  • Pingback: links for 2010-11-16 « Breyten’s Dev Blog()

  • G Man

    You mate, are a legend – thank you so much….

  • Uwe

    That’s why I love the internet so much, and of course you 😉

    • Haha, thank you! Me too 😀

  • Aziz

    Thanks dear! you made my work easy..

  • Thx a lot, you just made my day! Saved a lot of time!

  • I have collected the country name as comma separated string. Sometime when I need to generate a select box of countries, I just foreach() them by exploding it 😛

    • For a select box that’s fine. But I wanted to link to it in the database as well 🙂

  • LSH

    This is just what I was looking for! Thank you for posting this online for us. 🙂

  • sarjono

    Unfortunately, the world continues to break apart into smaller nations…
    Please add the following insertion:

    ('SS','AF', "South Sudan",'SSD','728',"Republic of South Sudan")

    and update the entry for Sudan with:

    ('SD', 'AF', "Sudan", 'SDN', '729', "Republic of Sudan")

    but I don’t know if updating Sudan’s numeric code from 736 to 729 is going to affect a database already in use. You may want to keep the old numeric code 736 if you already use it as an important index/key in your database relationships.

    Thanks for the initial efforts of making this table. You really helped me.

    • Thanks for the notice! Will do that as soon as I can. Not sure if it will have any effect (updating the numeric code that is), will look into it 🙂 Downloaded a document with some updates as well, need to update this page soon. Just haven’t gotten around to it yet :S

    • Working on updating it now. The numbering issue you mention shouldn’t be a problem unless someone has used the number as a key, rather than the two letter country code (which is used as primary key in the script).

    • Went through all the recent newsletters with updates and updated the post and the script. Hopefully it’s all correct now 🙂

  • MT

    Thank you very much for your hard work putting this together, it is really appreciated.

    I noticed that the full name of Taiwan differs from the ISO spec. This is fine with me since I’d rename it the same anyways, but since you mention ISO-3166, you might want to make a note that while the codes are correct, the country names might differ from the spec. Which they do. 🙂


    • Very good point. Hadn’t even noticed that! Will fix it ASAP 🙂

    • ASAP turned out to be a bit slow, but now it is fixed!

  • rere

    Thank u very much for saving my time , that exactlywhat i neeeeeeeed

  • Omprakash Patel

    Lots of Thanks for table of country according to continents ……………………..

  • brundibar

    Exactly what I was looking for! Thx a lot, c u.

  • Zhabba

    Thanks! Just in time!

  • Udhay

    Thanks a lot buddy 🙂

  • Thomas

    Thanks for the work.

    A small change in the name of Lybia see .

    UPDATE countries c SET name = 'Libya' WHERE code = 'LY';
    UPDATE countries c SET full_name = 'Libya' WHERE code = 'LY';
    • Oh, thanks for the heads up! Thought I had made an attemt to subscribe to those updates, but guess that didn’t work, hehe.

      Have updated the code on BitBucket and the post now, so it should all be correct again!

  • Michael

    Double Thank you! First, for doing it; second, for keeping it up to date!

    • You’re welcome! Let me know if I miss something 🙂

  • Antonio

    Really thanks for your work!!!

  • owner

    Woow, very nice post. Thanks 🙂 .

    PHP is a powerful tool for making dynamic and interactive Web pages – PHP Examples.

  • This db in spanish language?

    • Not that I know of. Think it might exist in French on the ISO website, but can’t remember having seen Spanish.

  • Thank you very much, your work is really helpful!

  • Amna

    Thank you so save my time

  • shivarajrh

    Thanks a lot for giving this sql file of countries.

    Matched my requirements.


  • Jeremy Moore


  • Reza

    Big Thanks. I saved my time. <3

  • Mauricio Bussab

    THANK YOU !!!

  • Piratacs

    Thanks for taking the time to share this. Really really helpful!

  • thanks very big.

  • Very nice! Thanks!

  • Pingback: php json_encode not working on arrays partiallyCopyQuery CopyQuery | Question & Answer Tool for your Technical Queries,CopyQuery, ejjuit, query, copyquery,, android doubt, ios question, sql query, sqlite query, nodejsquery, dns query, up()

  • Savin

    Thank you. 🙂

  • asdf

    you made my day 🙂

  • Pingback: php json_encode not working on arrays partially - Tech Magazine()

  • Pingback: mysql query not working for few variables passed from php script - Tech Magazine()

  • solomon

    thanks …….it full fill requirement i m very haapppppy………………

  • solomon

    Hi did you done an sql service for state for the countries