Professional Documents
Culture Documents
Mysql Slides
Mysql Slides
Web
MySQL Database System
Installation Overview
SQL summary
2-Tier Architecture
Web
Server
Web
Browser
(Client)
12/21/15
PHP
BGA
3-Tier Architecture
Web
Browser
(Client)
12/21/15
Web
Server
BGA
PHP
Database
Server
12/21/15
BGA
12/21/15
BGA
12/21/15
BGA
12/21/15
BGA
12/21/15
BGA
SQL links
Tutorials
http://www.w3schools.com/sql/
http://www.sqlzoo.net
http://sqlcourse.com (part 2)
http://sqlcourse2/com (part 1)
http://dev.mysql.com/doc/mysql/en/Refere
nce.html
12/21/15
BGA
Installation Summary
12/21/15
BGA
10
12/21/15
BGA
11
Client-Server Interaction
Make a request
(SQL query)
MySQL
Server
Get results
Client
Program
BGA
12
mysql -u root -p
you are prompted for the root password.
you can now send comands and SQL
statements to the server
12/21/15
BGA
13
WARNING WARNING
WARNING
12/21/15
BGA
14
SHOW DATABASES;
mysql> SHOW DATABASES;
+-------------+
| Database
|
+-------------+
| bookstore
|
| employee_db |
| mysql
|
| student_db |
| test
|
| web_db
|
+-------------+
12/21/15
BGA
15
USE test;
mysql> USE
test;
SHOW
tables;
Database changed
mysql> SHOW tables;
+----------------+
| Tables_in_test |
+----------------+
| books
|
| name2
|
| names
|
| test
|
+----------------+
4 rows in set (0.00 sec)
mysql>
12/21/15
BGA
16
DESCRIBE names;
12/21/15
BGA
17
12/21/15
BGA
18
BGA
19
Updating a record
BGA
20
Logging output
12/21/15
BGA
21
source c:\.....\books.sql
12/21/15
BGA
23
Documentation
c:\mysql\Docs\manual.html
c:\mysql\Docs\manual_toc.html
12/21/15
BGA
24
author
pub
year
price
books
table
12/21/15
rows
(records)
BGA
25
12/21/15
26
DATE
DATETIME
format YYYYMMDDHHMMSS
TIME
TIMESTAMP
format is YYYY-MM-DD
format HH:MM:SS
YEAR
12/21/15
default length is 4
BGA
27
String types
CHAR
VARCHAR
ENUM
12/21/15
BGA
28
SHOW
USE
12/21/15
BGA
29
BGA
30
BGA
31
BGA
32
12/21/15
BGA
33
Conditional Creation
12/21/15
BGA
34
DROP
DROP
DROP
DROP
DATABASE db_name;
DATABASE IF EXISTS db_name;
TABLE table_name;
TABLE IF EXISTS table_name;
BGA
35
BGA
36
12/21/15
BGA
37
12/21/15
BGA
38
12/21/15
BGA
39
12/21/15
BGA
40
marks.sql (1)
studentID first_name last_name
mark
marks
table
USE test;
CREATE TABLE marks (
studentID SMALLINT AUTO_INCREMENT NOT NULL,
first_name VARCHAR(20) NOT NULL,
last_name VARCHAR(20) NOT NULL,
mark SMALLINT DEFAULT 0 NOT NULL,
PRIMARY KEY (studentID)
);
12/21/15
BGA
41
marks.sql (2)
-- Insert some rows into marks table
INSERT INTO marks (first_name, last_name,
mark) VALUES ('Fred', 'Jones', 78);
INSERT INTO marks (first_name, last_name,
mark) VALUES ('Bill', 'James', 67);
INSERT INTO marks (first_name, last_name,
mark) VALUES ('Carol', 'Smith', 82);
INSERT INTO marks (first_name, last_name,
mark) VALUES ('Bob', 'Duncan', 60);
INSERT INTO marks (first_name, last_name,
mark) VALUES ('Joan', 'Davis', 86);
12/21/15
BGA
42
source
c:/.........../marks.sql
12/21/15
BGA
43
BGA
44
BGA
45
12/21/15
BGA
46
BGA
47
12/21/15
BGA
48
BGA
49
Quoting strings
12/21/15
BGA
50
12/21/15
BGA
51
12/21/15
BGA
52
12/21/15
BGA
53
12/21/15
BGA
54
12/21/15
BGA
55
12/21/15
BGA
56
books.sql (1)
isbn
title
author
pub
year
price
this is a
simple
design
books
table
USE web_db;
CREATE TABLE books (
isbn CHAR(15) PRIMARY KEY NOT NULL,
title VARCHAR(100) NOT NULL,
author VARCHAR(100) NOT NULL,
pub VARCHAR(20) NOT NULL,
year YEAR NOT NULL,
price DECIMAL(9,2) DEFAULT NULL
);
12/21/15
BGA
57
books.sql (2)
-- Insert some books into books table
INSERT INTO books VALUES ('0-672-31784-2',
'PHP and MySQL Web Development',
'Luke Welling, Laura Thomson',
'Sams', 2001, 74.95
);
INSERT INTO books VALUES ('1-861003-02-1',
'Professional Apache',
'Peter Wainwright',
'Wrox Press Ltd', 1999, 74.95
);
12/21/15
BGA
58
source
c:/.........../books.sql
12/21/15
BGA
59
employee_db.sql (1)
employeeID name
position
address
employeeID hours
employees
table
jobs
table
BGA
60
employee_db.sql (1)
CREATE TABLE employees (
employeeID SMALLINT NOT NULL,
name VARCHAR(20) NOT NULL,
position VARCHAR(20) NOT NULL,
address VARCHAR(40) NOT NULL,
PRIMARY KEY (employeeID)
);
INSERT INTO employees VALUES (1001, 'Fred',
'programmer', '13 Windle St');
INSERT INTO employees VALUES (1002, 'Joan',
'programmer', '23 Rock St');
INSERT INTO employees VALUES (1003, 'Bill',
'manager', '37 Front St');
12/21/15
BGA
61
employee_db.sql (2)
CREATE TABLE jobs (
employeeID SMALLINT NOT NULL,
hours DECIMAL(5,2) NOT NULL,
);
INSERT INTO jobs VALUES (1001, 13.5);
INSERT INTO jobs VALUES (1002, 2);
INSERT INTO jobs VALUES (1002, 6.25);
INSERT INTO jobs VALUES (1003, 4);
INSERT INTO jobs VALUES (1001, 1);
INSERT INTO jobs VALUES (1003, 7);
INSERT INTO jobs VALUES (1003, 9.5);
12/21/15
BGA
62
source
c:/......./employee_db.sql
12/21/15
BGA
63
12/21/15
BGA
64
|
1001 | Fred | programmer | 13 Windle St |
1003 | 4.00 |
|
1002 | Joan | programmer | 23 Rock St
|
1003 | 4.00 |
|
1003 | Bill | manager
| 37 Front St |
1003 | 4.00 |
|
1001 | Fred | programmer | 13 Windle St |
1001 | 1.00 |
|
1002 | Joan | programmer | 23 Rock St
|
1001 | 1.00 |
|
1003 | Bill | manager
| 37 Front St |
1001 | 1.00 |
|
1001 | Fred | programmer | 13 Windle St |
1003 | 7.00 |
|
1002 | Joan | programmer | 23 Rock St
|
1003 | 7.00 |
|
1003 | Bill | manager
| 37 Front St |
1003 | 7.00 |
|
1001 | Fred | programmer | 13 Windle St |
1003 | 9.50 |
|
1002 | Joan | programmer | 23 Rock St
|
1003 | 9.50 |
|
1003 | Bill | manager
| 37 Front St |
1003 | 9.50 |
+------------+------+------------+--------------+------------+-------+
21 rows in set (0.01 sec)
BGA
65
Substitution
12/21/15
BGA
66
12/21/15
BGA
67
12/21/15
BGA
68
12/21/15
BGA
69