MySQL provides many features that make it useful for storing, managing, and retrieving data. It supports relational databases, SQL queries, transactions, indexes, security features, stored procedures, triggers, and many other database capabilities.
MySQL is a Relational Database Management System (RDBMS).
It organizes data into tables made up of rows and columns.
Students
----------------
id | name | course
1 | Rahul| Python
2 | Amit | Java
MySQL uses SQL (Structured Query Language) for working with databases.
SQL can be used to create, retrieve, update, and delete data.
SELECT * FROM students;
MySQL provides SQL commands that allow developers to perform database operations using relatively simple and readable syntax.
CREATE DATABASE school;
USE school;
SELECT * FROM students;
MySQL is available as an open-source Community Edition.
This has helped make MySQL widely accessible to students, developers, and organizations.
MySQL is designed to provide good performance for many database workloads.
Indexes, query optimization, and suitable database design can help applications retrieve data efficiently.
MySQL can be used for small applications as well as larger systems.
Proper database design, indexing, hardware, configuration, and application architecture can help MySQL handle increasing workloads.
MySQL supports different storage engines.
One of the most important is InnoDB, which supports transactions and foreign keys.
InnoDB
MyISAM
Memory
CSV
MySQL with the InnoDB storage engine supports transactions.
Transactions allow multiple database operations to be treated as a logical unit of work.
START TRANSACTION;
UPDATE accounts
SET balance = balance - 100
WHERE id = 1;
COMMIT;
InnoDB transactions provide ACID properties:
These properties help maintain reliable transaction processing.
InnoDB supports foreign keys for creating relationships between tables.
CREATE TABLE orders (
id INT PRIMARY KEY,
student_id INT,
FOREIGN KEY (student_id)
REFERENCES students(id)
);
MySQL supports indexes that can help queries find rows more efficiently.
CREATE INDEX idx_name
ON students(name);
Indexes should be designed carefully because they also add storage and write overhead.
MySQL supports primary keys for uniquely identifying records.
CREATE TABLE students (
id INT PRIMARY KEY,
name VARCHAR(100)
);
MySQL supports constraints that help maintain data integrity.
MySQL supports many data types for different kinds of information.
INT
VARCHAR
DECIMAL
DATE
DATETIME
TEXT
BOOLEAN
Choosing an appropriate data type helps create an efficient database design.
MySQL supports several types for storing text and strings.
name VARCHAR(100)
description TEXT
String functions can also be used to manipulate text values.
MySQL provides data types and functions for working with dates and times.
DATE
TIME
DATETIME
TIMESTAMP
YEAR
These are useful for registrations, payments, attendance, orders, and other time-based information.
MySQL provides aggregate functions for calculations on groups of records.
COUNT()
SUM()
AVG()
MIN()
MAX()
For example:
SELECT COUNT(*) FROM students;
MySQL provides functions for working with text values.
UPPER()
LOWER()
CONCAT()
LENGTH()
TRIM()
For example:
SELECT UPPER(name)
FROM students;
MySQL provides functions for mathematical and numeric operations.
ROUND()
CEIL()
FLOOR()
ABS()
MOD()
POWER()
MySQL provides many functions for processing date and time values.
CURDATE()
NOW()
YEAR()
MONTH()
DAY()
DATE_FORMAT()
A view is a virtual table based on a SQL query.
CREATE VIEW student_view AS
SELECT id, name, course
FROM students;
Views can simplify frequently used queries and reports.
MySQL supports stored procedures for storing reusable SQL routines in the database.
CALL get_students();
Stored procedures can contain multiple SQL statements and parameters.
A trigger is a database object that automatically executes when a specified event occurs on a table.
Triggers can be associated with operations such as:
Modern MySQL versions provide a native JSON data type and functions for working with JSON documents.
CREATE TABLE products (
id INT PRIMARY KEY,
details JSON
);
MySQL provides features for managing database users and permissions.
Administrators can create users and grant specific privileges.
GRANT SELECT
ON school.students
TO 'student_user'@'localhost';
MySQL allows database administrators to control what users can do.
Privileges can include permissions such as:
MySQL supports replication, which can copy data from one MySQL server to another according to the configured replication setup.
Replication can be used for availability, scaling certain workloads, and other database architectures.
MySQL is available on multiple operating systems.
It can be used in development environments running platforms such as:
MySQL can be used with many programming languages and application technologies.
Examples include:
PHP
Python
Java
JavaScript / Node.js
C#
C++
MySQL provides a wide range of features for modern database applications.
MySQL
├── Relational Tables
├── SQL
├── Transactions
├── Foreign Keys
├── Indexes
├── Views
├── Stored Procedures
├── Triggers
├── Security
├── JSON Support
└── Replication
These features make MySQL suitable for many different database applications.
Question: Which MySQL storage engine supports transactions and foreign keys?