DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX.
-
Upload
delilah-oneal -
Category
Documents
-
view
219 -
download
2
Transcript of DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX.
![Page 1: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/1.jpg)
DATA BASE
ADMINISTRING DATABASE SERVICES IN RED HAT
LINUX
![Page 2: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/2.jpg)
DATA BASE TYPES
MySQL
PostgreSQL
![Page 3: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/3.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/4.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/5.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/6.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/7.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/8.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/9.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/10.jpg)
INSERTING VALUES
INSERT INTO phonebook VALUES (‘Doe’, ‘John’, ‘555-555-1212’);
![Page 11: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/11.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/12.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/13.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/14.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/15.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/16.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/17.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/18.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/19.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/20.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/21.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/22.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/23.jpg)
Creating a database in PostgreSQL
CREATE DATABASE animal;
OR createdb animals
![Page 24: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/24.jpg)
Creating a database user in PostgreSQL
CREATE USER usman; OR createuser usman
![Page 25: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/25.jpg)
Deleting a database user in PostgreSQL
DROP USER usman; OR dropuser usman
![Page 26: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/26.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/27.jpg)
Database clients
User Database Client Database Server
![Page 28: DATA BASE ADMINISTRING DATABASE SERVICES IN RED HAT LINUX.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/28.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/29.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/30.jpg)
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.](https://reader036.fdocuments.us/reader036/viewer/2022070414/5697c0071a28abf838cc614a/html5/thumbnails/31.jpg)
Changing a database and getting help
mysql> help;
mysql> use animals; database name