preload preload preload preload

Setting Up the world Database (Countries, States, Cites, etc)

In certain applications we need the details of all the counties in the world, all the states in in each country and the capital of all the country.  And it is difficult to create all theses information’s manually. But mysql provide a file world.sql which contains sample data for a world database that you can play with. This file contains names of all the Countries in the world, States, Cities, etc.  The file is available for download from the mysql site http://dev.mysql.com/doc. For more details about world.sql visit the site http://dev.mysql.com/doc/world-setup/en/world-setup.html.

To load the contents of the world.sql file into MySQL, use the following procedure:

  1. Change directory to where the world.sql file is locatedIf your current directory is not the same as the location of the world.sql file, use a cd command to change location.
  2. Connect to the MySQL server using the mysql programAt your command-line prompt, issue this command:
    shell> mysql -u root

    This command connects to the server using the MySQL root account to make sure that you’ll have permission to create the world database. The --p option tells mysql to prompt you for the root password. Enter the password when prompted. (Remember that the MySQL root account is not the same as the operating system root account and probably will have a different password.)

  1. Create the world database and select it as the default database:In the mysql program, issue the following statements:
    mysql> CREATE DATABASE world;
    mysql> USE world
  2. Load the contents of world.sql into the world databaseIssue a SOURCE command to tell mysql to read and process the contents of world.sql:
    mysql> SOURCE world.sql

    You’ll see quite a bit of output as mysql reads queries from the world.sql file and executes them.

After mysql finishes processing the world.sql file, try this statement:

mysql> SHOW TABLES;
+-----------————————--------------+
| Tables_in_world |
+-----------————————--------------+
| City            |
| Country         |
| CountryLanguage |
+-----------————————--------------+

The world tables contain the following types of information:

  • Country: Information about countries of the world.
  • City: Information about some of the cities in those countries.
  • CountryLanguage: Languages spoken in each country.

To see what columns each table contains, use DESCRIBE. For example:

mysql> DESCRIBE Country;
mysql> DESCRIBE City;
mysql> DESCRIBE CountryLanguage
  • Share/Bookmark
  • 3 responses to "Setting Up the world Database (Countries, States, Cites, etc)"

  • Vasile Ceteras
    17:38 on July 7th, 2010

    I couldn’t find the word.sql file nowhere on that page (http://dev.mysql.com/doc).

  • Vasile Ceteras
    17:39 on July 7th, 2010

    Actually, it’s at http://dev.mysql.com/doc/index-other.html .

    Thanks

  • Shahid
    20:05 on July 7th, 2010

    Hi Vasile,

    Yes you are right, I thing they changed the page. Thanks for informing the update.

  • Leave a Reply

    * Required
    ** Your Email is never shared