Importing to MySQL
With MySQL workbench
Download the
us-cities.zip
file using the unique download link we emailed to you after purchase. This link looks like:https://www.uscitieslist.org/download/xxxx-xxxx/
Once the download has finished double-click the
us-cities.zip
file and extract theus-cities/sql/us-cities.sql
script to your computer. Make a note of the location you extract theus-cities.sql
file to — you'll need it in step 5.Open MySQL workbench.
Select your database from the
MySQL Connections
list on the welcome screen and enter the password for your database user (if necessary). This will then open a newSQL Editor
window.Select
Server > Data Import
from the toolbar. Then underImport Options
chooseImport from Self-Contained File
and select theus-cities.sql
file you extracted in step 2. UnderDefault Target Schema
choose the database schema you want to import the data to.Click the
Start Import
button at the bottom of the screen. The script will create a new table calledus_cities
and insert the data. This typically takes a few seconds to complete.Once the import has finished you can query the
us_cities
table. Double-click the name of the database schema that you imported the data to under theSchemas
section of the sidebar, then selectFile > New Query Tab
and type your query. For example:SELECT * FROM us_cities LIMIT 50;
Select
Query > Execute Current Statement
from the toolbar to run your query and see the results.
With the Terminal (Mac & Linux)
Press
CTRL+ALT+T
to open a new terminal window.Download the
us-cities.zip
file using the unique download link we emailed to you after purchase. You can do this with thewget
command:$ wget -O us-cities.zip https://www.uscitieslist.org/download/xxxx-xxxx/
Once the download has finished decompress the
us-cities.zip
file. You can do this with theunzip
command:$ unzip us-cities.zip
Use the
msql
command to run theus-cities/sql/us-cities.sql
import script, taking care to set the default character set toUTF-8
. For example to import the data into theexample_db
database as theroot
user you should use the command below.$ mysql -u root -p --default-character-set=utf8 example_db < us-cities/sql/us-cities.sql
Once the import is complete you can query the data. Connect to your database using the
mysql
command again:$ mysql -u root -p example_db
Then at the
mysql
prompt type your query and hit enter to run it. For example:mysql> SELECT * FROM us_cities LIMIT 10;