Download link:# Assignment 1: SQL Startup
Description
5/5 – (2 votes)
Do the following and then upload a .pdf file.
- Install the correct version (Windows vs. Mac vs. Linux) of MySQL: dev.mysql.com/downloads/m…
- Make sure it works. Here is an example of commands to try. Mac users: Use Terminal under Applications/Utilities. Windows users: Use the command prompt.
Unix commands to find and start using MySQL:
cd /usr/local/mysql/bin
./mysql -u root -p
- When it asks for a password, just press Return. For older installations, by default, there is no password.
- The newest installation sets a root password; you should see a prompt during the installation. Note/record this password.
- You may want to change the root password like this (which changes the root password to “ilovesql”):
ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘ilovesql’ ;
Now that you are inside of MySQL, see what databases exist, create one, then connect to it with the “use” command.
show databases ;
create database test ;
show databases ;
use test ;
Now that we are connected to “test,” see what tables exist (none), create a table, use the “describe” command to see its properties, insert some data, and then select some data.
show tables ;
create table students (id int primary key, name varchar(20) not null, age int) ;
show tables ;
describe students ;
insert into students values( “1”, “Bob”, “18”) ;
insert into students values(“2”, “Bob”, “19”) ;
insert into students values(“3”, “Bob”,NULL) ;
select * from students ;
insert into students values(“3”, “Sue”, 20) ;
insert into students values(“4”, NULL, 21) ;
- Upload proof that you got it working.
After you have made sure it works, upload to a .txt or .pdf file something that shows you got it to work. Below is an example of showing this. You can grab screenshots, cut and paste, or
use the Unix command “script,” which creates a file called typescript that shows a log of what you typed in and the responses you received. Note, to exit script, just type exit.
———- Example typescript file from the above commands
Script started on Sun Jan 12 09:50:17 2014
[?1034hbash-3.2$ tcsh
- cd /usr/local/mysql/bin
- ./mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 126299
Server version: 5.6.15 MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> show databses[K[K[Kases ;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| performance_schema |
+——————–+
3 rows in set (0.00 sec)
mysql> crdate[K[K[K[Keae[Kte databae[Kse test ;
Query OK, 1 row affected (0.01 sec)
mysql> show databases ;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| performance_schema |
| test |
+——————–+
4 rows in set (0.00 sec)
mysql> use test ;
Database changed
mysql> show tables ;
Empty set (0.00 sec)
mysql> create table students (id int primary key, name varchar(20) not null, age int) ; Query OK, 0 rows affected (0.02 sec)
| mysql> show tables ; | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| +—————- | + | ||||||||||||
| Tables_in_test | |||||||||||||
| +—————- | + | ||||||||||||
| students | |||||||||||||
| +—————- | + | ||||||||||||
| 1 row in set (0.00 sec) | |||||||||||||
| mysql> describe students ; | |||||||||||||
| +——- | +————- | +—— | +—– | +——— | +——- | + | |||||||
| Field | Type | Null | Key | Default | Extra | ||||||||
| +——- | +————- | +—— | +—– | +——— | +——- | + | |||||||
| id | int(11) | NO | PRI | NULL | |||||||||
| name | varchar(20) | NO | NULL | ||||||||||
| age | int(11) | YES | NULL | ||||||||||
| +——- | +————- | +—— | +—– | +——— | +——- | + |
3 rows in set (0.00 sec)
mysql> insert into students values( “1”, “Bob”, “18”) ; Query OK, 1 row affected (0.01 sec)
mysql> insert into students values(“2”, “Bob”, “19”) ; Query OK, 1 row affected (0.00 sec)
mysql> insert into students values(“3”, “Bob”,NULL) ; Query OK, 1 row affected (0.00 sec)
mysql> select * from students ;
| +—- | +—— | +—— | + | ||||
|---|---|---|---|---|---|---|---|
| id | name | age | |||||
| +—- | +—— | +—— | + | ||||
| 1 | Bob | 18 | |||||
| 2 | Bob | 19 | |||||
| 3 | Bob | NULL | |||||
| +—- | +—— | +—— | + |
3 rows in set (0.00 sec)
mysql> insert into students values(“3”, “Sue”, 20) ;
ERROR 1062 (23000): Duplicate entry ‘3’ for key ‘PRIMARY’
mysql> insert into students values(“4”, NULL, 21) ;
ERROR 1048 (23000): Column ‘name’ cannot be null
mysql> quit ;
Bye
[63] exit
exit
bash-3.2$ x[Kexit
exit
Script done on Sun Jan 12 09:52:49 2019