Apache | IIS | Nginx | Node | |
---|---|---|---|---|
Concurrency Model | threaded/process-oriented
approach (inefficient memory use and scheduling) |
asynchronous event-driven approach (no blocking, more scalable) |
||
Common Programming Language | PHP | ASP.NET/PHP | None/PHP | JavaScript |
Design Goals | full-featured generic purpose |
less
features, serve specific purpose (e.g., cache/proxy) |
specific
purpose app framework bundled w/ web server |
|
Open-source | yes | proprietary | yes | yes |
Web Server Survey (a go-to website for major news for web servers)
Reference: Amazon EC2 Auto Scaling User Guide: Amazon EC2 Auto Scaling benefits
Reference: Cloud computing (Wikipedia)
Ref: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/concepts-webserver.html
DEFAULT
valueCHECK(logicExpr)
1. connecting to server via SSH
2. install software: For Redhat: sudo yum install mysql -y
for Debian/Ubuntu: $ sudo apt-get install mysql-server mysql-client
3. start the mysql server: $ mysql -u root -p -h <your-db>.rds.amazonaws.com
eb ssh
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 26
Server version: 5.5.40-log Source distribution
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> CREATE USER 'shopXX-admin' IDENTIFIED BY 'mypass';
mysql> CREATE DATABASE shopXX;
mysql> SHOW DATABASES;
mysql> GRANT ALL ON shopXX.* TO 'shopXX-admin';
mysql> exit;
- There are some tables (mysql, schema) that you do not want to mess up with
mysql -u shopXX-admin -p -h
[YourHostName]<your-db>.rds.amazonaws.com
USE shopXX;
shopXX-admin
is granted full access to DB called
shopXX
mysql> DROP USER shopXX-admin
shopXX-admin@localhost
will fail because we'd support
remote logins from the EC2- Creating a Table ``categories''
mysql> CREATE TABLE categories (
catid INTEGER PRIMARY
KEY AUTO_INCREMENT, name VARCHAR(512) NOT NULL
) ENGINE=INNODB;
mysql> DESCRIBE
categories;
mysql> DROP TABLE categories;
mysql> TRUNCATE categories; /* To drop/delete all the data*/
mysql> CREATE TABLE products (
pid INTEGER PRIMARY KEY AUTO_INCREMENT,
catid INTEGER,
name VARCHAR(512),
price ______________,
description _____________,
FOREIGN KEY(catid)
REFERENCES categories(catid)
) ENGINE=INNODB;
catid
to make subsequent
queries by it faster
mysql> CREATE INDEX i1 ON products(catid);
Question: What is INDEX?
Reference: Data types supported by MySQL
- Note: put null for the primary key to let it auto-increment
mysql> INSERT INTO categories VALUES (null, "Fruits");
- To insert 2 records into products
mysql> INSERT INTO products
VALUES (null, 1, "Apple", "1.5");
mysql> INSERT INTO products (catid, name, price)
VALUES (1, "Banana", "1.5");
- Try to insert a product to an inexistent category:
mysql> INSERT INTO products (catid, name, price)
VALUES (2, "Help", "999");
- Error: constraint failed
- Note: This error is expected given that the foreign key setting
More on SQL INSERT:
http://dev.mysql.com/doc/en/insert.html - To select all "fruits" in products (given fruits is of catid=1)
mysql> SELECT *
FROM products WHERE
catid = 1;
- To select only the name and price columns
mysql> SELECT name, price FROM products WHERE catid = 1;
- To select only 5 "fruits" in products
mysql> SELECT * FROM products WHERE catid = 1 LIMIT 5;
- To select the 11-20th most expensive "fruit" products
mysql> SELECT * FROM products
WHERE catid = 1
ORDER
BY price DESC
LIMIT 11, 10;
- Recall: For those frequently-queried columns, create INDEX (trading off space for speed)
More on SQL SELECT:
http://dev.mysql.com/doc/en/select.html - Setting a static value
mysql> UPDATE categories
SET name = "Fresh Fruits"
WHERE catid = 1;
-Setting an expression (e.g., 10% increase in price)
mysql> UPDATE products
SET price = price * 1.1
WHERE pid = 2;
mysql> DELETE FROM categories WHERE catid = 1;
mysql> DELETE FROM products WHERE pid = 2;