0% found this document useful (0 votes)
14 views

Database Server

Databse Server

Uploaded by

Abhishek Chomal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Database Server

Databse Server

Uploaded by

Abhishek Chomal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Mariadb Installa on and Management

Name:- Abhishek Chomal


 This document provides a comprehensive guide on se ng up
and managing a MariaDB database server. It covers
installa on steps, user management, and database backup
and restore procedures. Below is a structured overview of the
main sec ons included in this guide.

1. MariaDB Installa on: This sec on provides a step-by-


step guide to installing MariaDB on RHEL 9. It includes
upda ng system packages, installing MariaDB, securing
the installa on (by se ng a root password, removing
anonymous users, etc.), and crea ng a sample database
and tables.

2. User Management: It explains how to create new users,


assign different levels of privileges (like full access, read-
only, or specific access), and check or revoke these
privileges. It also covers how to log in as a specific user
and verify their permissions, ensuring that they can only
perform ac ons allowed by their assigned privileges.

3. Backup and Restore:This part shows how to back up a


MariaDB database using mysqldump, which saves the
database to a SQL file. The process also includes crea ng
a new empty database, restoring data from the backup
file into this database, and verifying the successful
restora on of data.

Name:- Abhishek Chomal


What is MariaDB ?
MariaDB is an open-source, rela onal database management system
(RDBMS) that manages data using predefined rela onships. It
organizes data as tables, columns, and rows. Below are the concise
steps to install, configure, and set up a basic database in MariaDB,
followed by key features.

Features of MariaDB:-

1.High Performance: Enhanced op miza on features for improved


speed and performance over MySQL.

2.Open Source: Free to use with regular updates from a large


developer community.

3.Compa bility: Backward compa bility with MySQL, allowing easy


migra on from MySQL to MariaDB.

4.Security: Strong encryp on for data in transit and at rest.

5.Scalability: Supports large-scale enterprise applica ons with


features like sharding and par oning.

6.High Availability: Master-slave replica on, clustering, and Galera


Cluster support for con nuous availability.

7.Storage Engines: Support for various storage engines like InnoDB


(ACID-compliant), MyISAM, and more for flexibility in data handling.

8.SQL Standards Compliance: MariaDB follows standard SQL


prac ces, ensuring easy development and integra on.

Name:- Abhishek Chomal


Use Cases of MariaDB:-

1.Web Applica ons: MariaDB is widely used to manage databases for


web applica ons like content management systems (CMS), e-
commerce pla orms, and customer rela onship management (CRM)
systems.

2. Enterprise Data Management: Used for managing vast amounts of


data in industries like finance, telecom, and healthcare.

3. Cloud Databases: MariaDB is popular for cloud-based solu ons,


especially with integra ons for AWS, Google Cloud, and Microso
Azure.

4. Data Warehousing: It can be used for analy cs and repor ng,


handling complex queries and large datasets.

Name:- Abhishek Chomal


Step by Step Installing MariaDB-Server

Step 1: Update System Packages


 Ensure your RHEL 9 system is updated to avoid dependency
issues.
 Command: yum update -y

Step 2: Install MariaDB (Database) Server


 Package name: mariadb-server
 Command: yum install mariadb-server -y

Step 3: Start the MariaDB service and enable it to start on boot


 Service name: mariadb
 Command: systemctl start mariadb

 Command: systemctl enable mariadb

Name:- Abhishek Chomal


Step 4: Secure Your MariaDB Installa on
 For be er security, run the mysql_secure_installa on script
to remove default se ngs that could pose security risks
(e.g., default users, test databases):
 Command: mysql_secure_installa on

Follow the on-screen prompts:


 Set a root password.
You will be prompted to enter a new password for the
MariaDB root user. Enter a strong password and confirm it.

Name:- Abhishek Chomal


 Remove anonymous users.
You will be asked if you want to remove anonymous users.
Type Y (yes) and press Enter.

 Disallow root login remotely.


You will be prompted to disallow root login remotely. Type Y
(yes) and press Enter.

 Remove test databases.


You will be asked if you want to remove the test database
and access to it. Type Y (yes) and press Enter.

 Reload privileges.
Finally, you will be prompted to reload the privileges table.
Type Y (yes) and press Enter.

Name:- Abhishek Chomal


Step 5: You can log into MariaDB with
 Command: mysql -u root -p
 Enter your MariaDB root password when prompted.

Step 6: Create Database


 To confirm the setup, create a sample database.
 Command: create database organiza on;

Step 7: Show Database


 Check Database create or not
 Command: show databases;

Name:- Abhishek Chomal


Step 8: Switch in the Database
 First, switch to the database you want to work on.
 Command: use organiza on;

Step 9: Now create a table within this database


 Command:
CREATE TABLE employees (id INT AUTO_INCREMENT
PRIMARY KEY, name VARCHAR (50) NOT NULL,
department VARCHAR (50), salary DECIMAL(10,2) );

Step 10: You can check the table structure using


 Command: DESCRIBE employees;

Step 11: Insert Records into the Table


 Command: INSERT INTO employees (name, department,
salary) VALUES ('Abhishek', 'IT', 45000.00), ('Aman', 'HR',
55000.00), ('Amar', 'Finance', 50000.00);

Name:- Abhishek Chomal


Step 12: Verify the inserted records
 Command: SELECT * FROM employees;

Step 13: Create another Database


 Command: CREATE DATABASE produc on;

Step 14: Verify Database


 Command: show databases;

Name:- Abhishek Chomal


Step 15: Switch Database in produc on
 Command: USE produc on;

Step 16: Create mul ple tables in produc on database


 Command:
CREATE TABLE products (product_id INT

AUTO_INCREMENT PRIMARY KEY, product_name

VARCHAR (50), price DECIMAL (8,2));

CREATE TABLE orders (order_id INT AUTO_INCREMENT

PRIMARY KEY,product_id INT, order_date DATE, quan ty

INT, FOREIGN KEY(product_id) REFERENCES

products(product_id));

Name:- Abhishek Chomal


Step 17: Verifying tables
 Command: show tables;

Step 18: Inser ng Records into the products Table


 Command:
INSERT INTO products (product_name, price) VALUES
('Laptop', 95000.00),('Smartphone', 40000.00),
('Headphones', 2500.00),('Smartwatch', 6000.00),
('Monitor', 14000.00),('Keyboard', 700.00),
('Mouse', 600.00),('External Hard Drive', 5000.00);

Name:- Abhishek Chomal


Step 18: Inser ng Records into the orders Table
 Since the orders table has a foreign key (product_id) that
references the products table, you'll need to ensure that the
product_id values match the ones from the products table.
For example, if the product_id for the Laptop is 1, the
Smartphone is 2, etc., you can insert records like this.
 Command:
INSERT INTO orders (product_id, order_date, quan ty)

VALUES

(1, '2024-10-20', 2), (2, '2024-09-21', 3), (3, '2024-10-23', 5),

(4, '2024-08-25', 1), (5, '2024-10-24', 2),(6, '2024-10-25', 10),

(7, '2024-09-28', 8), (8, '2024-10-27', 4);

Step 19: Verifying the records of both tables:-


 Command: select * from products;

Name:- Abhishek Chomal


 Command: select * from orders;

Crea ng Users: -
You can create new users using the CREATE USER command. Let’s
create a user named Abhishek, Rahul & Amar and assign a
passwords to them:
 Command:
CREATE USER 'Abhishek'@'localhost' IDENTIFIED BY 'Abhishek';
CREATE USER 'Rahul'@'localhost' IDENTIFIED BY 'Rahul';
CREATE USER 'Amar'@'localhost' IDENTIFIED BY 'Amar';

Name:- Abhishek Chomal


Gran ng Permissions to Users: -
You can now grant different types of permissions to users.
 Grant all privileges to Abhishek (full access to the database):
 Command:
GRANT ALL PRIVILEGES ON organiza on.* TO
'Abhishek'@'localhost';

 Grant only SELECT privileges (read-only access):


 Command:
GRANT SELECT ON produc on.orders TO 'Rahul'@'localhost';

 Grant INSERT and UPDATE privileges:


 Command:
GRANT INSERT, UPDATE ON produc on.orders TO
'Amar'@'localhost';

 Grant All privileges on the par cular table of any database:-


 Command:
GRANT ALL PRIVILEGES ON produc on.products TO
'Abhishek'@'localhost';

Name:- Abhishek Chomal


Apply Privileges: -
A er gran ng permissions, you need to apply the changes:
 Command: FLUSH PRIVILEGES;

Check Granted Privileges for a User: -


 To check which privileges a user has:
 Command: SHOW GRANTS FOR 'Abhishek'@'localhost';

 Command: SHOW GRANTS FOR 'Rahul'@'localhost';

 Command: SHOW GRANTS FOR 'Amar'@'localhost';

 Command: SHOW GRANTS FOR 'root'@'localhost';

Name:- Abhishek Chomal


Revoke Privileges from a User: -
Step 1: Remove the User’s Privileges:
 If you need to remove or revoke specific privileges from a user,
use the REVOKE command.
 Command:
REVOKE INSERT, UPDATE ON produc on.orders FROM
'Amar'@'localhost';

Step 2: Save Changes


 Run the FLUSH PRIVILEGES command apply the changes.
 Command: FLUSH PRIVILEGES;

Step 3: Verify
 Check Privileges a er remove privileges.
 Command: SHOW GRANTS FOR 'Amar'@'localhost';

Name:- Abhishek Chomal


Access the Database as a Normal User: -
 To access the database as Abhishek, log out from the current
user and log in as the new user.
Step 1: Log In as the New User
 Command: mysql -u Abhishek -p

 Once logged in, you can only access the databases and tables
for which Abhishek has privileges.

Step 2: Check the User's Privileges


 A er Log in Check the User's Privileges.
 Command: SHOW GRANTS;

Step 3: Switch to the Database


 Switch to the database the user has permissions for, such as.
 Command: USE organiza on;

Name:- Abhishek Chomal


Step 4: Check Tables in the Database
 Show List all tables in the database to confirm what the user
can access.
 Command: SHOW TABLES;

Step 5: View Data in the Tables


 Now, the user can view data in specific tables. For example, to
see data in the employees table.
 Command: SELECT * FROM employees;

Note: If the user only has SELECT privileges, a emp ng to INSERT or


UPDATE data will result in a permission error, like are as follows:

This ensures the user cannot exceed their assigned permissions.

Name:- Abhishek Chomal


You can check same as for other users:-
 Login with Rahul user and verify the permissions we given.

Delete user:-
Step 1: Delete the User
 To delete the user account completely, use the following
command.
 Command: DROP USER 'Amar'@'localhost';

Name:- Abhishek Chomal


Mysql Dump
 MariaDB Backup and Restore Using mysqldump
MariaDB mysqldump is a u lity for backing up and restoring
databases. It exports databases into a file containing SQL statements
that can be used to recreate the database structure and data on
another server. This is useful for database migra on, maintenance,
or disaster recovery.
Step 1: Backup the Database
 To create a backup of the organiza on database, use the
following command:
 Command: mysqldump -u root -p organiza on >
organiza on_backup.dump.

Step 2: Verify Backup


 A er the backup is created, verify it by lis ng the files in the
current directory using ls command.
 Command: ls

Name:- Abhishek Chomal


Step 3: Create a New Empty Database for Restora on
 Log in to Mariadb as the root user to create the empty
database.
 A er logged in, create a new empty database named
org_backup
 Command: CREATE DATABASE org_backup;

 Verify Database Command: show databases;

Step 4: Restore the Backup to the New Database


 Restore the backup file organiza on_backup.dump to the
newly created org_backup database.
 Command: mysql -u root -p org_backup <
organiza on_backup.dump.

Name:- Abhishek Chomal


Step 5: Verify Restora on
 Switch to the org_backup database and check the tables.
 Command: USE org_backup;
SHOW TABLES;
SELECT * FROM employees;

MariaDB was successfully installed, configured, and managed for


efficient data handling and backup.

Name:- Abhishek Chomal

You might also like