Mysql & Apache Web Server: Huy Nguyen
Mysql & Apache Web Server: Huy Nguyen
Huy Nguyen
1 http://www.tel4vn.com/
Outline
l MYSQL
l APACHE
2 http://www.tel4vn.com/
MYSQL
Database and Database Management System
l Database is simply a collection of data. In relational database,
3 http://www.tel4vn.com/
MYSQL(cont)
MySQL Introduction
l MySQL is a database management system
l SQL stands for the Structured Query Language. It defines how
to insert, retrieve, modify and delete data
l Free from www.mysql.com
Installation:
l Ubuntu: apt-get install mysql-server mysql-client
l CentOS: yum -y install mysql mysql-server mysql-devel
Set root password:
l CentOS: mysqladmin -u root password 'htkdb1234'
l Ubuntu: ask root password when installing
4 http://www.tel4vn.com/
MYSQL(cont)
Basic MySQL Operations
l Create table
l Insert records
l Load data
l Retrieve records
l Update records
l Delete records
l Modify table
l Join table (option)
l Drop table
l Optimize table (option)
l Count, Like, Order by, Group by (option)
l More advanced ones (procedures, triggers, views …) (option)
5 http://www.tel4vn.com/
MYSQL(cont)
Login
l Command: mysql –h hostname –u username –p
l Example:
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 307
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
6 http://www.tel4vn.com/
MYSQL(cont)
Create database:
l mysql> create database freeswitch;
Database changed
l mysql> show tables;
identified by ‘Passw0rd';
l mysql> flush privileges;
7 http://www.tel4vn.com/
MYSQL(cont)
Create table
CREATE TABLE `cdr` (
`current_channel` varchar(80) NOT NULL default '0',
`next_room` int(6) NOT NULL default 0,
`move_time` datetime NOT NULL default '0000-00-00 00:00:00',
KEY `current_channel` (`current_channel`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
8 http://www.tel4vn.com/
MYSQL(cont)
Display table structure:
l mysql> use freeswitch;
Database changed
l mysql> show tables;
+----------------------+
| Tables_in_freeswitch |
+----------------------+
| cdr |
+----------------------+
1 row in set (0.00 sec)
9 http://www.tel4vn.com/
MYSQL(cont)
Display table structure (cont)
mysql> describe cdr;
+-----------------+-------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------------------+-------+
| current_channel | varchar(80) | NO | MUL | | |
| next_room | int(6) | NO | | 0 | |
| move_time | datetime | NO | | 0000-00-00 00:00:00 | |
+-----------------+-------------+------+-----+---------------------+-------+
3 rows in set (0.00 sec)
10 http://www.tel4vn.com/
MYSQL(cont)
Modify table structure:
Command: ALTER TABLE table_name Operations
l mysql> ALTER TABLE cdr add enable int(6) NOT NULL default 0;
l mysql> describe cdr;
+-----------------+-------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------------------+-------+
| current_channel | varchar(80) | NO | MUL | | |
| next_room | int(6) | NO | | 0 | |
| move_time | datetime | NO | | 0000-00-00 00:00:00 | |
| enable | int(6) | NO | | 0 | |
+-----------------+-------------+------+-----+---------------------+-------+
11 http://www.tel4vn.com/
MYSQL(cont)
Insert record
l mysql> insert into cdr(current_channel,next_room,move_time,enable)
values('abc123','50','2012-03-26 10:30:01','1');
Query OK, 1 row affected (0.01 sec)
Retrieve record
l Command: SELECT what_columns FROM table or tables WHERE
condition
l mysql> select * from cdr;
+-----------------+-----------+---------------------+--------+
| current_channel | next_room | move_time | enable |
+-----------------+-----------+---------------------+--------+
| abc123 | 50 | 2012-03-26 10:30:01 | 1 |
+-----------------+-----------+---------------------+--------+
1 row in set (0.00 sec)
12 http://www.tel4vn.com/
MYSQL(cont)
Update record
l Command: UPDATE table_name SET which columns to change WHERE
condition
l mysql> update cdr set next_room='100' where current_channel='abc123';
+-----------------+-----------+---------------------+--------+
| current_channel | next_room | move_time | enable |
+-----------------+-----------+---------------------+--------+
| abc123 | 100 | 2012-03-26 10:30:01 | 1 |
+-----------------+-----------+---------------------+--------+
13 http://www.tel4vn.com/
MYSQL(cont)
Delete record:
l Command: DELETE FROM table_name WHERE condition
l mysql> delete from cdr where current_channel='abc123';
Query OK, 1 row affected (0.01 sec)
l mysql> select * from cdr;
Empty set (0.00 sec)
14 http://www.tel4vn.com/
MYSQL(cont)
Drop table:
Command: DROP TABLE table_name
l mysql> drop table cdr;
Query OK, 0 rows affected (0.00 sec)
l mysql> show tables;
Empty set (0.00 sec)
Drop database:
l mysql> drop database freeswitch;
Exit MYSQL:
l mysql> exit or mysql> quit;
15 http://www.tel4vn.com/
MYSQL(cont)
Backup database
l Command: mysqldump -u username -p database_name >
backup_file
[root@appliance ~]# mysqldump -u root -p freeswitch > dump.sql
Enter password:
Restore from mysql dump file
l Command: mysql -u username -p < dump_file
16 http://www.tel4vn.com/
MYSQL(cont)
Reset mysql root password
l Stop mysql:
password=PASSWORD(‘new_password’) WHERE
user=’root’;
17 http://www.tel4vn.com/
WEBSERVER
What is a Web Server? And What is HTTP?
A Web Server is any Machine that receives requests from a client machine and is able
l
to turn around process the requests and send back a response. This is usually in terms of
a Web Server to send back a Web pages when people what to go navigate to a webpage
that is hosted on that server now one may ask how do you send and receive the
information to and from the server. This is where HTTP begins to play a role into how
this all goes about.
l HTTP Protocol: HTTP stands for Hyper-Text-Transfer-Protocol
l This is the protocol that is used in order to send and receive information from the
server. This is the protocol that the Apache Web Server Understands and it is what it
uses to send information back to the client Machine. If you would want to get a bit
more technical on the subject the Client Machine this case the Browser sends a
HTTP.Request Object to the Server then the Server responds back by using an
HTTP.Response Object. This is the general back and forth between the server and the
browser. Apache is made to handle all of these requests.
18 http://www.tel4vn.com/
WEBSERVER (cont)
Client-Server Interactions
As we stated before the Client makes an HTTP
request to the server in this case the Apache Web
server then the server handles the server pools
the connections to it, by the basic instructions
within the Apache Core then the server sends
back a response. Many people do not realize that
they be utilizing an Apache web server everyday
since it is the most popular web server out right
now. When you go online and request a webpage.
Most likely an Apache Web server is processing
your request and then it is sending you back the
webpage you requested.
19 http://www.tel4vn.com/
WEBSERVER (cont)
l Apache2
l Httpd
20 http://www.tel4vn.com/
WEBSERVER (cont)
Apache Overview
Diagram
As you can see the
designers of Apache
decided to take a
modular approach so
that anyone can add to
the basic functionality
of the server without
disturbing the basic
Core implementation.
21 http://www.tel4vn.com/
WEBSERVER (cont)
l Install:
l apache2: apt-get install apache2
- /etc/apache2/apache2.conf (main)
- /etc/apache2/sites-available/
- /etc/apache2/sites-enabled/
l httpd: /etc/httpd/conf/httpd.conf
22 http://www.tel4vn.com/
WEBSERVER (cont)
l Default document root:
l apache2: /var/www/
25 http://www.tel4vn.com/
WEBSERVER (cont)
Example:
Alias /siremis/ "/var/www/siremis-x.y.z/siremis-web/"
<Directory "/var/www/siremis-x.y.z/siremis-web/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
RedirectMatch ^/siremis/$ /siremis/bin/
<Files ~ "\.inc$">
Order allow,deny
Deny from all
</Files>
</Directory>
26 http://www.tel4vn.com/
Reference
http://www.mysqltutorial.org/
http://httpd.apache.org/docs/2.4/
http://code.tutsplus.com/articles/apache-2-basic-
configuration-on-unix-like-systems--net-26607
27 http://www.tel4vn.com/