Database Operations
Core Database Management Concepts
MariaDB provides comprehensive database operations through SQL commands, enabling efficient data management and manipulation across various applications.
graph LR
A[Database Operations] --> B[Create]
A --> C[Read]
A --> D[Update]
A --> E[Delete]
Key SQL Operations
Operation |
Command |
Purpose |
Database Creation |
CREATE DATABASE |
Initialize new database |
Table Creation |
CREATE TABLE |
Define data structure |
Data Insertion |
INSERT INTO |
Add new records |
Data Retrieval |
SELECT |
Query and fetch data |
Data Modification |
UPDATE |
Modify existing records |
Data Deletion |
DELETE |
Remove specific records |
Practical Examples
## Create a new database
CREATE DATABASE employee_management;
## Use the database
USE employee_management;
## Create a table
CREATE TABLE staff (
id INT PRIMARY KEY,
name VARCHAR(100),
department VARCHAR(50),
salary DECIMAL(10,2)
);
## Insert data
INSERT INTO staff VALUES
(1, 'John Doe', 'IT', 5000.00),
(2, 'Jane Smith', 'HR', 4500.00);
## Query data
SELECT * FROM staff WHERE department = 'IT';
## Update record
UPDATE staff SET salary = 5500.00 WHERE id = 1;
## Delete record
DELETE FROM staff WHERE id = 2;
Security Considerations
## Create database user
CREATE USER 'dbadmin'@'localhost' IDENTIFIED BY 'strong_password';
## Grant specific privileges
GRANT ALL PRIVILEGES ON employee_management.* TO 'dbadmin'@'localhost';
## Flush privileges
FLUSH PRIVILEGES;