DEV Community

King coder
King coder

Posted on • Edited on

πŸ“˜ BCA SEM 3 – RDBMS USING MYSQL (CIITM Dhanbad)

️⃣ UNIT – I : Introduction, Installation, SQL Commands, Logs


⭐ 1. Introduction to MySQL

  • MySQL is an open-source relational database (RDBMS).
  • Stores data in tables (rows & columns).
  • Uses SQL language to manage data.
  • Fast, secure, free, and widely used.

⭐ 2. Installing MySQL

A. Windows Installation

  1. Download MySQL Installer (MSI).
  2. Run Setup β†’ Developer Default.
  3. Set root password.
  4. Install MySQL Server + Workbench.
  5. Open Workbench to connect.

B. Linux Installation Methods

βœ” RPM Installation

sudo rpm -ivh mysql.rpm
sudo systemctl start mysqld
Enter fullscreen mode Exit fullscreen mode

βœ” Binary Installation

  1. Download .tar.gz
  2. Extract files
  3. Set permissions
  4. Start server manually with mysqld &

βœ” Source Installation

cmake .
make
sudo make install
Enter fullscreen mode Exit fullscreen mode

⭐ 3. Starting & Stopping MySQL

Start MySQL (Linux - 4 Ways)

sudo systemctl start mysqld
sudo service mysql start
/etc/init.d/mysql start
mysqld &
Enter fullscreen mode Exit fullscreen mode

Stop MySQL

sudo systemctl stop mysqld
mysqladmin -u root -p shutdown
Enter fullscreen mode Exit fullscreen mode

⭐ 4. Basic SQL Queries

DML

INSERT, UPDATE, DELETE, SELECT
Enter fullscreen mode Exit fullscreen mode

DDL

CREATE, ALTER, DROP, TRUNCATE
Enter fullscreen mode Exit fullscreen mode

TCL

COMMIT, ROLLBACK, SAVEPOINT
Enter fullscreen mode Exit fullscreen mode

⭐ 5. Types of Joins

  • INNER JOIN
  • LEFT JOIN
  • RIGHT JOIN
  • FULL JOIN
  • SELF JOIN

⭐ 6. UNION

Combines result of 2 SELECT queries.


⭐ 7. MySQL Logs & Uses

Log Type Description
Error Log Server startup/shutdown errors
General Query Log All SQL queries
Slow Query Log Queries taking long time
Binary Log (binlog) All changes (used for replication & backup)
Relay Log Copy of binlog on slave

Binlog Formats:
βœ” Statement
βœ” Row
βœ” Mixed


πŸ“˜ UNIT – II : Client Programs, Workbench, Upgrading, Locking


⭐ 1. MySQL Server/Client Architecture

  • Client sends SQL commands
  • Server executes queries and returns results

⭐ 2. MySQL Client Programs

  • mysql
  • mysqladmin
  • mysqldump
  • mysqlshow
  • mysqlimport

⭐ 3. Non-Client Programs

  • mysqld β†’ MySQL server
  • mysqld_safe
  • mysql_install_db

⭐ 4. Upgrading MySQL

Why Upgrade?

  • Bug fixes
  • Security
  • New features
  • Better speed

Upgrade Checklist

  • Take full backup
  • Stop MySQL server
  • Install new version
  • Verify data compatibility

⭐ 5. mysqladmin Commands

Command Use
mysqladmin shutdown Stop server
mysqladmin ping Check server status
mysqladmin flush-logs Rotate logs

⭐ 6. MySQL Workbench

  • GUI tool for running queries
  • Database design (ER diagrams)
  • User management
  • Backup/restore

⭐ 7. MySQL Locking

Type Description
Internal Locking Handled by MySQL automatically
Table-Level Locking Locks whole table
Row-Level Locking Locks specific row
External Locking Done by OS
Deadlock Two transactions wait for each other

πŸ“˜ UNIT – III : Table Maintenance, Schemas, Backup, Replication


⭐ 1. Table Maintenance Commands

Command Purpose
ANALYZE TABLE Update statistics
CHECK TABLE Detect errors
REPAIR TABLE Fix corrupted table
OPTIMIZE TABLE Improve performance
CHECKSUM TABLE Generate checksum
BACKUP TABLE Backup table data
RESTORE TABLE Restore table

⭐ 2. Information Schema

  • Stores metadata
  • Important tables:

    • TABLES
    • COLUMNS
    • STATISTICS
    • SCHEMATA

⭐ 3. Performance Schema

Used for:

  • Query performance
  • I/O monitoring
  • Memory usage

⭐ 4. MySQL Backup & Recovery

Backup Types

  • Logical (mysqldump)
  • Physical (copying files)
  • Hot Backup
  • Cold Backup

Commands

mysqldump -u root -p db > backup.sql
Enter fullscreen mode Exit fullscreen mode

Load Data

LOAD DATA INFILE 'file.csv' INTO TABLE table;
Enter fullscreen mode Exit fullscreen mode

Export

SELECT * INTO OUTFILE 'data.csv' FROM students;
Enter fullscreen mode Exit fullscreen mode

⭐ 5. MySQL Replication

What is Replication?

Copying data from one server (Master) to another (Slave).

Types

  • Master-Slave
  • Master-Master
  • Circular replication

Architecture Components

  • Binary Log
  • Relay Log
  • I/O Thread
  • SQL Thread

⭐ 6. MySQL User Management

CREATE USER 'u'@'localhost' IDENTIFIED BY 'p';
DROP USER 'u';
RENAME USER 'old' TO 'new';
GRANT SELECT ON db.* TO 'u';
REVOKE ALL PRIVILEGES ON db.* FROM 'u';
Enter fullscreen mode Exit fullscreen mode

⭐ 7. Routines & Triggers

Stored Procedure

Reusable SQL code.

Function

Returns a value.

Trigger

Runs automatically on:

  • INSERT
  • UPDATE
  • DELETE

πŸ“˜ UNIT – V : Memory, Security, Optimization


⭐ 1. Resource Allocation

MySQL uses memory for:

  • Query cache
  • Sorting
  • Joins
  • Buffers
  • Connections

Monitor using:

SHOW STATUS;
Enter fullscreen mode Exit fullscreen mode

⭐ 2. Securing MySQL

Operating System Security

  • Use strong OS passwords
  • Disable unnecessary accounts

File System Security

  • Protect /var/lib/mysql/
  • Correct file permissions

Network Security

  • Disable remote root login
  • Use firewall
  • Allow only trusted IPs

Log Security

  • Protect binlogs and slow logs

⭐ 3. Query Optimization

Steps:

  1. Identify slow queries
  2. Use EXPLAIN
  3. Add indexes
  4. Avoid SELECT *
  5. Normalize tables
  6. Use LIMIT

EXPLAIN

EXPLAIN SELECT * FROM students WHERE age > 20;
Enter fullscreen mode Exit fullscreen mode

SHOW WARNINGS

Shows errors and warnings.


πŸ“ IMPORTANT EXAM QUESTIONS (Most Repeated)


UNIT – I

  1. Explain different MySQL installation methods.
  2. What are DDL, DML, TCL commands?
  3. Explain MySQL logs and their uses.
  4. What are joins? Explain types of joins.

UNIT – II

  1. Explain MySQL Server/Client Architecture.
  2. What are mysqladmin commands?
  3. What is locking? Explain table-level and row-level locking.
  4. What is MySQL Workbench?

UNIT – III

  1. Explain table maintenance commands.
  2. Information schema vs performance schema.
  3. Explain MySQL backup and recovery.
  4. Explain replication architecture.
  5. What are routines and triggers?

UNIT – V

  1. Explain MySQL resource allocation.
  2. What are security measures in MySQL?
  3. What is query optimization?
  4. Explain EXPLAIN and SHOW WARNINGS.

Top comments (0)