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:
- Change directory to where the
world.sqlfile is locatedIf your current directory is not the same as the location of theworld.sqlfile, use a cd command to change location. - Connect to the MySQL server using the mysql programAt your command-line prompt, issue this command:
shell>
mysql -u rootThis command connects to the server using the MySQL
rootaccount to make sure that you’ll have permission to create theworlddatabase. The--poption tells mysql to prompt you for therootpassword. Enter the password when prompted. (Remember that the MySQLrootaccount is not the same as the operating systemrootaccount and probably will have a different password.)
- Create the
worlddatabase and select it as the default database:In the mysql program, issue the following statements:mysql>
CREATE DATABASE world;mysql>USE world - Load the contents of
world.sqlinto theworlddatabaseIssue aSOURCEcommand to tell mysql to read and process the contents ofworld.sql:mysql>
SOURCE world.sqlYou’ll see quite a bit of output as mysql reads queries from the
world.sqlfile 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
Posted by Shahid