Mysql
Mysql
What is MySQL?
MySQL is currently the most popular database management system software used
for managing the relational database.
It is open-source database software, which is supported by Oracle Company.
It is fast, scalable, and easy to use database management system in comparison
with Microsoft SQL Server and Oracle Database.
It is commonly used in conjunction with PHP scripts for creating powerful and
dynamic server-side or web-based enterprise applications.
---xxx---
What is RDBMS (Relational Database Management System)
All modern database management systems like SQL, MS SQL Server, IBM
DB2, ORACLE, My-SQL, and Microsoft Access are based on RDBMS.
The following are the various terminologies of RDBMS:
What is table/Relation?
Everything in a relational database is stored in the form of relations. The
RDBMS database uses tables to store data. A table is a collection of
related data entries and contains rows and columns to store data. Each
table represents some real-world objects such as person, place, or event
about which information is collected. The organized collection of data into
a relational table is known as the logical view of the database.
Properties of a Relation:
o Each relation has a unique name by which it is identified in the
database.
o Relation does not contain duplicate tuples.
o The tuples of a relation have no specific order.
o All attributes in a relation are atomic, i.e., each cell of a relation
contains exactly one value.
A table is the simplest example of data stored in RDBMS.
Let's see the example of the student table.
Degree:
The total number of attributes that comprise a relation is known as the
degree of the table
For example, the student table has 4 attributes, and its degree is 4.
Cardinality:
The total number of tuples at any one time in a relation is known as the
table's cardinality. The relation whose cardinality is 0 is called an empty
table.
For example, the student table has 5 rows, and its cardinality is 5.
Domain:
The domain refers to the possible values each attribute can contain. It can be
specified using standard data types such as integers, floating numbers,
etc. For example, An attribute entitled Marital_Status may be limited to
married or unmarried values.
NULL Values
The NULL value of the table specifies that the field has been left blank during
record creation. It is different from the value filled with zero or a field that
contains space.
Data Integrity
There are the following categories of data integrity exist with each RDBMS:
o Entity integrity: It specifies that there should be no duplicate rows in a
table.
o Domain integrity: It enforces valid entries for a given column by
restricting the type, the format, or the range of values.
o Referential integrity specifies that rows cannot be deleted, which are
used by other records.
o User-defined integrity: It enforces some specific business rules defined
by users. These rules are different from the entity, domain, or referential
integrity.
---xxx---
MySQL is a Relational Database Management System (RDBMS) software that
provides many things, which are as follows:
It allows us to implement database operations on tables, rows, columns, and
indexes.
It defines the database relationship in the form of tables (collection of rows
and columns), also known as relations.
It provides the Referential Integrity between rows or columns of various
tables.
It allows us to updates the table indexes automatically.
It uses many SQL queries and combines useful information from multiple
tables for the end-users.
MySQL follows the working of Client-Server Architecture. This model is designed for the
end-users called clients to access the resources from a central computer known as a
server using network services. Here, the clients make requests through a graphical user
interface (GUI), and the server will give the desired output as soon as the instructions are
matched. The process of MySQL environment is the same as the client-server model.
The core of the MySQL database is the MySQL Server. This server is available as a
separate program and responsible for handling all the database instructions, statements,
or commands. The working of MySQL database with MySQL Server are as follows:
MySQL creates a database that allows you to build many tables to store and
manipulate data and defining the relationship between each table.
Clients make requests through the GUI screen or command prompt by using
specific SQL expressions on MySQL.
Finally, the server application will respond with the requested expressions and
produce the desired result on the client-side.
Reasons for popularity
MySQL is becoming so popular because of these following reasons:
o MySQL is an open-source database, so you don't have to pay a single penny to use
it.
o MySQL is a very powerful program that can handle a large set of functionality of
the most expensive and powerful database packages.
o MySQL is customizable because it is an open-source database, and the open-
source GPL license facilitates programmers to modify the SQL software according
to their own specific environment.
o MySQL is quicker than other databases, so it can work well even with the large
data set.
o MySQL supports many operating systems with many languages like PHP, PERL, C,
C++, JAVA, etc.
o MySQL uses a standard form of the well-known SQL data language.
o MySQL is very friendly with PHP, the most popular language for web development.
o MySQL supports large databases, up to 50 million rows or more in a table. The
default file size limit for a table is 4GB, but you can increase this (if your operating
system can handle it) to a theoretical limit of 8 million terabytes (TB).
Features of MySQL
One of the major reasons MySQL is considered one of the most popular relational
databases is because of its abundant features. Let us look at them one by one –
Open-Source - MySQL is open-source, which means this software can be
downloaded, used and modified by anyone. It is free-to-use and easy-to-
understand.
Quick and Reliable - MySQL stores data efficiently in the memory ensuring that
data is consistent, and not redundant. Hence, data access and manipulation using
MySQL is quick.
High Performance - MySQL provides comparatively higher performance without
affecting its functionality. It also has a very little memory leakage making it
memory efficient as well.
Scalable - Scalability refers to the ability of systems to work easily with small
amounts of data, large amounts of data, clusters of machines, and so on. MySQL
server was developed to work with large databases.
Data Types - It contains multiple data types such as unsigned integers, signed
integers, float (FLOAT), double (DOUBLE), character (CHAR), variable character
(VARCHAR), text, blob, date, time, datetime, timestamp, year, and so on.
Character Sets - It supports different character sets, and this includes latin1
(cp1252 character encoding), German, Ujis, other Unicode character sets and so
on.
Secure - It provides a secure interface since it has a password system which is
flexible, and ensures that it is verified based on the host before accessing the
database. The password is encrypted while connecting to the server.
Support for large databases- It comes with support for large databases, which
could contain about 40 to 50 million records, 150,000 to 200,000 tables and up to
5,000,000,000 rows.
Platform Independent - MySQL can be run on various operating systems including
Windows, Linux, macOS etc. in several programming languages like C, C++, Java,
Python, Perl, PHP etc.
BIT(size) A bit-value type. The number of bits per value is specified in size. The size parameter can
hold a value from 1 to 64. The default value for size is 1.
TINYINT(size) A very small integer. Signed range is from -128 to 127. Unsigned range is from 0 to 255.
The size parameter specifies the maximum display width (which is 255)
SMALLINT(size) A small integer. Signed range is from -32768 to 32767. Unsigned range is from 0 to 65535.
The size parameter specifies the maximum display width (which is 255)
MEDIUMINT(size) A medium integer. Signed range is from -8388608 to 8388607. Unsigned range is from 0 to
16777215. The size parameter specifies the maximum display width (which is 255)
INT(size) A medium integer. Signed range is from -2147483648 to 2147483647. Unsigned range is
from 0 to 4294967295. The size parameter specifies the maximum display width (which is
255)
FLOAT(size, d) A floating point number. The total number of digits is specified in size. The number of digits
after the decimal point is specified in the d parameter. This syntax is deprecated in MySQL
8.0.17, and it will be removed in future MySQL versions
FLOAT(p) A floating point number. MySQL uses the p value to determine whether to use FLOAT or
DOUBLE for the resulting data type. If p is from 0 to 24, the data type becomes FLOAT().
If p is from 25 to 53, the data type becomes DOUBLE()
DOUBLE(size, d) A normal-size floating point number. The total number of digits is specified in size. The
number of digits after the decimal point is specified in the d parameter
DOUBLE
PRECISION(size, d)
DECIMAL(size, d) An exact fixed-point number. The total number of digits is specified in size. The number of
digits after the decimal point is specified in the d parameter. The maximum number
for size is 65. The maximum number for d is 30. The default value for size is 10. The
default value for d is 0.
CHAR(size) A FIXED length string (can contain letters, numbers, and special characters).
The size parameter specifies the column length in characters - can be from 0
to 255. Default is 1
VARCHAR(size) A VARIABLE length string (can contain letters, numbers, and special
characters). The size parameter specifies the maximum column length in
characters - can be from 0 to 65535
BINARY(size) Equal to CHAR(), but stores binary byte strings. The size parameter specifies
the column length in bytes. Default is 1
VARBINARY(size) Equal to VARCHAR(), but stores binary byte strings. The size parameter
specifies the maximum column length in bytes.
TINYBLOB For BLOBs (Binary Large OBjects). Max length: 255 bytes
BLOB(size) For BLOBs (Binary Large OBjects). Holds up to 65,535 bytes of data
LONGBLOB For BLOBs (Binary Large OBjects). Holds up to 4,294,967,295 bytes of data
ENUM(val1, val2, val3, ...) A string object that can have only one value, chosen from a list of possible
values. You can list up to 65535 values in an ENUM list. If a value is inserted
that is not in the list, a blank value will be inserted. The values are sorted in
the order you enter them
SET(val1, val2, val3, ...) A string object that can have 0 or more values, chosen from a list of possible
values. You can list up to 64 values in a SET list
DATETIME(fsp) A date and time combination. Format: YYYY-MM-DD hh:mm:ss. The supported
range is from '1000-01-01 00:00:00' to '9999-12-31 23:59:59'. Adding DEFAULT
and ON UPDATE in the column definition to get automatic initialization and
updating to the current date and time
TIMESTAMP(fsp) A timestamp. TIMESTAMP values are stored as the number of seconds since
the Unix epoch ('1970-01-01 00:00:00' UTC). Format: YYYY-MM-DD hh:mm:ss.
The supported range is from '1970-01-01 00:00:01' UTC to '2038-01-09
03:14:07' UTC. Automatic initialization and updating to the current date and
time can be specified using DEFAULT CURRENT_TIMESTAMP and ON UPDATE
CURRENT_TIMESTAMP in the column definition
YEAR A year in four-digit format. Values allowed in four-digit format: 1901 to 2155,
and 0000.
MySQL 8.0 does not support year in two-digit format.