Skip to content

Demo - Week 2

Part 1 - Log in to MySQL and view some data

  • Bring up a terminal or console window

  • Use wget to get the .sql file northwind.sql.txt:

1
wget https://phpwebdevmysql.com/files/northwind.sql
  • Log into your mysql server:
1
$ mysql -u student -p

You are now in the mysql command line interface (CLI):

1
>
  • Create the northwind database with the following command:
1
> create database northwind;
  • Exit the mysql CLI by typing:
1
> exit

You are now back in the Bash shell:

1
$ 
  • With the database created import the database files (we downloaded) with the following commands:
1
mysql -u student -p northwind < northwind.sql
  • Log back into your mysql server:
1
$ mysql -u student -p
  • Direct your mysql client to use the northwind database:
1
> use northwind;
  • List out all the tables:
1
> show tables;
  • Describe all the columns in a table:
1
> describe Products;
  • How many tables are there in the northwind database? ______

  • How many products are in the products table? ______

  • What is the unit price for the row with a product_name of Chai ______

Part 2 - Create a table in your own database schema

  • Bring up a terminal or console window

  • Log into your mysql server:

1
$ mysql -u student -p
  • Create a database using your MadisonCollege username. In this example I use my username of kemarks1:
1
2
> create database kemarks1;
> use kemarks1;
  • Create a table named fullname using the following statement:
1
> CREATE TABLE fullname ( first_name varchar(20), last_name varchar(20) );
  • Insert a row into the table fullname using the following statement:
1
> INSERT INTO fullname (first_name, last_name) VALUES ('Ken', 'Marks');
  • Insert two more rows into the table using the same syntax as above. Use any values you wish.

  • Run the statement below and show your instructor the results:

1
> SELECT * FROM fullname;
  • Exit the mysql client by typing:
1
> exit