31
DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

Embed Size (px)

Citation preview

Page 1: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

DATA BASE

ADMINISTRING DATABASE SERVICES IN RED HAT

LINUX

Page 2: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

DATA BASE TYPES

MySQL

PostgreSQL

Page 3: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

Responsibilities of a DBA

1. Installing & maintaining database servers Installing patches Upgrading softwares

2. Installing & maintaining database clients Installing & maintaining client programs

3. Maintaining accounts and users. Adding /deleting users from the database

4. Ensuring Database security Access control permissions

5. Ensuring data integrity Protects data changes and avoids duplication in multiple

users

Page 4: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

FORMS OF DATABASE

1. Flat FilesSimple text files having Space Tab Other characters

Example: /etc/passwd

2. Relations The are also called RDBMSExample: Spreadsheets

Page 5: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

FLAT FILES

LIMITATIONS/ DISADVANTAGES 1. Do not scale wellCannot perform random access on dataSearch line by line (only sequential access)

2. Unsuitable for multi user environments.Simultaneous changes by two users can lead to

overwriting

Page 6: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

RDBMS

ADVANTAGES

Very good at finding relationships between data

Stores data in tables with fields which makes searching and sorting data easy.

Page 7: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

SQL BASICS

Database languageVery similar to English and so it’s very simpleSQL statements have a defined structureEnd users are unaware of it

Page 8: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

CREATING A TABLE IDEA

Different column types for dataSpecial column types e.g DATE , VAR,

VARCHAR etc..SQL commands are not case sensitiveWhitespace is generally ignoredSQL statement terminates with a semi colon

(;)

Page 9: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

CREATING A TABLE . 1

CREATE TABLE phonebook(Last_name VARCHAR (25) NOT NULL,First_name VARCHAR (25) NOT NULL,Phone INT (20) NOT NULL);

Page 10: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

INSERTING VALUES

INSERT INTO phonebook VALUES (‘Doe’, ‘John’, ‘555-555-1212’);

Page 11: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

TABLE VIEW

Last_name First_name Phone

Doe John 555-555-1212

Doe Jane 555-666-1313

Pawl John 123-456-7890

Johnson Richard 111-222-3333

phonebook

Page 12: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

DISPLAYING DATA

SELECT * FROM phonebook;SELECT first_name FROM phonebook;SELECT Last_name, Phone FROM

phonebook;SELECT CONCAT(First_name, “ ” ,

Last_name) AS Name FROM phonebook; Name

John Doe

Jane Doe

John Pawl

Richard Johnson

Page 13: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

DISPLAYING DATA

SELECT * FROM phonebook WHERE first_name= “John”;

OPPOSITE

SELECT * FROM phonebook WHERE first_name!= “John”;

Page 14: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

CHOOSING A DATABASE: MySQL V PostgreSQL

SPEED: MySQL is faster as compare to PostgreSQL. Queries are executed and results are

displayed faster Data Locking: PostgreSQL is better then MySQL MySQL locks the whole table when some

one is accessing a single field where as PostgreSQL just locks the raw which is currently being accessed, the rest whole table is open and unlock.

Page 15: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

Locking table in MySQL and PostgreSQL

PostgreSQL

Last_name First_name Phone

Doe John 555-555-1212

Doe Jane 555-666-1313

Pawl John 123-456-7890

Johnson Richard 111-222-3333

PostgreSQL

MySQL

Page 16: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

PostgreSQL IS ACID COMPLIANCE

Atomicity: If you have a power failure or server crash after an original record

has been deleted but before the updated one has been added , you done lose the record because atomic transaction ensure that the original record is not deleted unless and untill the new record is added.

new record to be added(before crash)

Record recovered Deleted old record before crash

Page 17: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

PostgreSQL IS ACID COMPLIANCE

Consistency:

Incomplete transactions are rolled back to maintain consistency.

Isolation:

Ensures that multiple transactions operating on the same data are completely isolated from each other. Prevents data corruption if two users try to write to the same record . (locking )

Durability: If server crashed the database examines the log file and makes the changes accordingly .

Page 18: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

Procedural Languagesor

imperative language

PostgreSQL , C++, JAVA , SQL

Programming Languages

PHP, Pearl, Visual Basic

Page 19: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

Installing and configuring MySQL

Two ways for installing and configuring1- Source Version 2- Binary RPM (MySQL-server and MySQL-client)

i- Install it by rpm –i command.

ii- Initialize the grand tables by mysql_install_db command as root user.

iii- Go to mysql environment by typing mysql command . iv- Setting a password for MySQL root user by mysql> SET

PASSWORD FOR root = PASSWORD (“secretword”); command inside mysql environment.

v- type exit command to exit mysql environment . NOTE: Once installed through RPM , necessary user and group

is created automatically by the name MySQL .

Page 20: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

Creating a database in MySQL

mysql> CREATE DATABASE animal; OR mysqladmin –u root –p create animals

Page 21: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

Granting and Taking away Privileges in MySQL

GRANT ALL ON animals.* TO usman IDENTIFIED BY ‘usman123’;

REVOKE ALL on animals FROM usman; Database User

Database All table User Password

Page 22: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

Installing and configuring PostgreSQL

Two ways for installing and configuring1- Source Version 2- Binary RPM (postgresql, postgresql-server and postgresql-libs)

i- Install it by rpm –i command.

ii- Create the data directory by mkdir /usr/local/pgsql command as root user. iii- Then change the user ownership of data directory to postgres user by typing chown

postgres /use/local/pgsql command as root user. iv- Then change the group ownership of data directory to postgres group by typing chgrp

postgres /use/local/pgsql command as root user . v- Then change your self to a postgres user by the command su- postgres in order to initialize the data directories. vi- To initialize give the command initdb –D /user/local/pgsql/data . vii- Now start the database server by the command /usr/bin/postmaster –D

/usr/local/pgsql/data OR /usr/bin/pg_ctl -D /usr/local/pgsql/data –l logfile start viii- At the end issue the command postmaster –D /usr/local/pgsql/data & NOTE: Once installed through RPM , necessary user and group is created automatically

by the name postgres .

Page 23: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

Creating a database in PostgreSQL

CREATE DATABASE animal;

OR createdb animals

Page 24: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

Creating a database user in PostgreSQL

CREATE USER usman; OR createuser usman

Page 25: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

Deleting a database user in PostgreSQL

DROP USER usman; OR dropuser usman

Page 26: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

Granting and Taking away Privilages in PostgreSQL

GRANT ALL ON animals TO usman ;

REVOKE ALL on animals FROM usman; Database User

Database User

Page 27: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

Database clients

User Database Client Database Server

Page 28: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

Database clients model 1

User Database Client Database Server

Your local host Remote host

Page 29: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

Database clients model 2

User Database Client Database Server

Your local host Remote host 1 Remote host 2

Page 30: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

Database clients model 3

UserWeb Browser

Database Client Web Server

Database Server

Your local host Remote host 1 Remote host 2

Page 31: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX

Changing a database and getting help

mysql> help;

mysql> use animals; database name