0% found this document useful (0 votes)
10 views53 pages

DOC-20250604-WA0029.

MySQL is an open-source relational database management system that utilizes Structured Query Language (SQL) for data management and is supported by Oracle. It allows users to perform various database operations, such as creating and manipulating tables, and is known for its speed, scalability, and compatibility with multiple programming languages and operating systems. The document also covers MySQL's installation process, structure, field types, and features, highlighting its popularity and various editions available.

Uploaded by

crushpra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views53 pages

DOC-20250604-WA0029.

MySQL is an open-source relational database management system that utilizes Structured Query Language (SQL) for data management and is supported by Oracle. It allows users to perform various database operations, such as creating and manipulating tables, and is known for its speed, scalability, and compatibility with multiple programming languages and operating systems. The document also covers MySQL's installation process, structure, field types, and features, highlighting its popularity and various editions available.

Uploaded by

crushpra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 53

UNIT-III

MySQL
MySQL is a relational database management system based on the Structured Query Language, which is the popular
language for accessing and managing the records in the database. MySQL is open-source and free software under
the GNU license. It is supported by Oracle Company.

Our MySQL tutorial includes all topics of MySQL database that provides for how to manage database and to
manipulate data with the help of various SQL queries. These queries are: insert records, update records, delete
records, select records, create tables, drop tables, etc. There are also given MySQL interview questions to help you
better understand the MySQL database.

What is Database?
It is very important to understand the database before learning MySQL. A database is an application that stores the
organized collection of records. It can be accessed and manage by the user very easily. It allows us to organize data
into tables, rows, columns, and indexes to find the relevant information very quickly. Each database contains
distinct API for performing database operations such as creating, managing, accessing, and searching the data it
stores. Today, many databases available like MySQL, Sybase, Oracle, MongoDB, PostgreSQL, SQL Server, etc. In
this section, we are going to focus on MySQL mainlyPrime Ministers of India | List of Prime Minister of India
(1947-2020)

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.

It is developed, marketed, and supported by MySQL AB, a Swedish company, and written in C programming
language and C++ programming language. The official pronunciation of MySQL is not the My Sequel; it is My Ess
Que Ell. However, you can pronounce it in your way. Many small and big companies use MySQL. MySQL supports
many Operating Systems like Windows, Linux, MacOS, etc. with C, C++, and Java languages.

MySQL is a Relational Database Management System (RDBMS) software that provides many things, which are as
follows:

o​ It allows us to implement database operations on tables, rows, columns, and indexes.


o​ It defines the database relationship in the form of tables (collection of rows and columns), also known as
relations.
o​ It provides the Referential Integrity between rows or columns of various tables.
o​ It allows us to updates the table indexes automatically.
o​ It uses many SQL queries and combines useful information from multiple tables for the end-users.

How MySQL Works?


o​ 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:

1.​ MySQL creates a database that allows you to build many tables to store and manipulate data and
defining the relationship between each table.
2.​ Clients make requests through the GUI screen or command prompt by using specific SQL
expressions on MySQL.
3.​ Finally, the server application will respond with the requested expressions and produce the desired
result on the client-side.

A client can use any MySQL GUI. But, it is making sure that your GUI should be lighter and user-friendly to
make your data management activities faster and easier. Some of the most widely used MySQL GUIs are
MySQL Workbench, SequelPro, DBVisualizer, and the Navicat DB Admin Tool. Some GUIs are commercial,
while some are free with limited functionality, and some are only compatible with MacOS. Thus, you can
choose the GUI according to your needs.

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).

History of MySQL
The project of MySQL was started in 1979 when MySQL's inventor Michael Widenius developed an in-house
database tool called UNIREG for managing databases. After that, UNIREG has been rewritten in several
different languages and extended to handle big databases. After some time, Michael Widenius
contacted David Hughes, the author of mSQL, to see if Hughes would be interested in connecting mSQL to
UNIREG's B+ ISAM handler to provide indexing to mSQL. That's the way MySQL came into existence.

MySQL is named after the daughter of co-founder Michael Widenius whose name is "My".

Features of MySQL
There are various features of MySQL. Some of them are:

●​ It is based on SQL.
●​ It is open source and freely available.
●​ User-friendly and compatible with PHP, which means you can easily connect with PHP and create a
website and share which can be connected easily and manipulate databases. For example, using
XAMPP you can install PHP and MySQL.Create a new database in MySQL and connect both of them
using PHP my admin.
●​ It is based on client-server architecture.
●​ It’s very secure and flexible as it’s one of the most secure database systems.
●​ It is scalable and supports large databases, for example, you can create 50 million rows or more in a
table, the default file size limit for a table is 4GB and it can be increased according to the
requirements.
●​ It is also compatible with major operating systems like Windows, Mac, and Linux.

Editions of MySQL

There are five types of MySQL editions, these are discussed below:

●​ MySQL Enterprise Edition- There are several MySQL editions available to business customers to
meet specific and advanced technical requirements.
●​ MySQL Standard Edition- MySQL Standard Edition allows you to deliver good performance and
easy Online Transaction Processing (OLTP) applications.
●​ MySQL Classic Edition- It is the embedded database for ISVs, OEMs, and VARs developing
applications. It is determined that it has the best performance and zero administration database.
●​ MySQL Cluster Carrier Grade Edition- It is a distributed database combining easier scalability and
also for its availability.
●​ MySQL Embedded(OEM/ISV)- Over 2000 ISVs, OEMs, and VARs calculate MySQL as their
product’s database to make their operations, tackle, and appliances more competitive, bring them to
request, and lower their COGs( cost of Goods sold).

●​ Installation of MySQL – MySQL Installer

Step 1: At first you need to go to the official website of MySQL(mysql.com) and scroll down.
You will see an option to select Operating System.​
You need to choose Microsoft Windows.
Step 2: Then you will see two options to download. You can select one of them or you can take a
reference from the below image.
Step 3: Once you click on the download option, you will be redirected to the next page and you
will have to click on the “No thanks, just start my download” option.​
After that, you will see that MySQL Installer is getting downloaded.

Step 4: Once, MySQL Installer gets downloaded, you need to open that and you will see that the MySQL
installer Community is getting installed.
Then you will see the following screen. Next, all you need to do is to click on the radio button which is
asking for the acceptance of the license terms. After

that, click on Next.

Step 5: In the next process, you have to choose the setup type.

This means that you have to choose which features you wish to install. So, choose the Full button and
click on Next.

This process installs all of the products that are available in this catalog including MySQL Server, MySQL
Shell, MySQL Router, MySQL Workbench, MySQL Connectors, documentation, samples and examples,
and much more.
Step 6: In the next step, you will see that some of the features may fail to install due to a lack of
requirements.

So, either you can fix them, or can skip them, by clicking on Next as it willn’t interrupt the installation
process.

So, click on Next.

Next, you will see a dialog box asking for your confirmation of a few products not getting installed.

So, you can just click on Yes.

Next, you will see the list of the products which will get installed.

So you can go ahead and click on the Execute option, which we highlighted in the below image.
After clicking on the Execute option, you will see that the products are getting installed.

Once the installation process shows complete, click on Next.

Next, you have to configure the Server and Router. After that click on Next.

Step 7: Based on your requirement, you can either choose the Standalone MySQL Server/ Classic
MySQL Replication or the InnoDB Cluster.​
We clicked on the Standalone MySQL Server/ Classic MySQL Replication option and then click on Next.
Step 8: Once, you click on Next, you will get the Type and Networking page where you have to mention
the Server Configuration Type.

We left it as it is and then click on Next, you can take reference from the below image.

Step 9: Now, you will get to the Authentication Method page where you have to choose the authentication
mode.

Here, you can choose the first option as given in the below image, and click on Next.

Step 10: Next, you have to make the MySQL Root Password and then repeat the same password and
then click on Next.

●​ Remember the password that you have mentioned or you can take note of that password for the
future.
Step 11: After that, you will get the Windows Service page where you have to choose whether you want
to start the MySQL Server at system startup or not. Here, we are keeping it as it is and has not changed
anything.

Click on Next.

After clicking on Next, you will get the Apply Configuration page where you will get a list of the
configurations that you want to execute to apply the changes from the list of these configurations.

So, if you agree with these configurations click on Execute.


After the execution is done, click on Finish. This will finish the configuration of the Server.

Step 12: On the next page you can choose to configure the Router.​
So click on click on Finish.

Step 13: Once, you click on Finish, you will see the Connect to server page.

Here you have to give the root password, which you set earlier.

Now, you have to check if the connection is successful, by clicking on the Check button.

Then after the configuration is completed, click on Next.


Step 14: After clicking on Next, you will get the Apply Configuration page, where you can choose the
configurations that are applied and then click on Execute.

Step 15: In the next step, you will see the screen which is given below.​
After the configurations get applied, click on Finish.

Here, you can check on the page that the installation procedure has been completed.
Step 16: After completing all of the above steps and procedures, you can finally check if MySQL has
been installed or not.

Now you just have to open MySQL Shell and fill in your root password.

The above output shows that MySQL has been installed in your system.

MySQL structure and syntax


MySQL is a relational database system, stores bits of information in separate areas and links those
areas together.

Store virtually anything in a database example:- address book, product catalog.

MySQL Structure
MySQL allows separating information into tables or “areas of pertinent information.”

In non-relational database systems, all the information is stored in one big area, which makes it much
more difficult and bulky to sort and extract required data.

In MySQL, each table consists of separate fields, which represent each bit of information.

For example, the field customer’s first name, and another field could contain his last name.
Fields can hold different types of data, such as text, numbers, dates, and so on.

Database tables based on what type of information to store in them.

The separate “areas” or tables of MySQL are then linked together with some common denominator,
where the values of the common field are the same.

Example:- customer table that includes a customer’s name, address, and ID number, and another table
that includes the customer’s ID number and past orders he has placed. The common field is the
customer’s ID number, and the information stored in the two separate tables would be linked together
via fields where this number is equal. This enables us to see all the information related to this
customer at one time.

Field Types
When you create a table initially, need to tell the MySQL server what types of information will be stored

in each field.

The different types of fields and some examples are listed in the table that follows.
In brief

❑ Less than 255 characters, fixed-length: Use char.

❑ 1–255 characters, variable length: Use varchar if you want to delete any trailing spaces, or if want to
set a default value. Use tiny text if don’t care about trailing spaces or a default value or if your text does
not need to be case-sensitive. Use a tiny blob if don’t care about trailing spaces or a default value, but
your text does need to be case-sensitive.

❑ 256–65536 characters: Use text if your text does not need to be case-sensitive in searches, sorts, or
comparisons, use blob if the text is case-sensitive.

❑ 65537–1677215 characters: Use medium text if the text does not need to be case sensitive, use
mediumblob if the text is case-sensitive.

❑ 1677216–4294967295 characters: Use long text if the text does not need to be case sensitive, use long
blob if the text is case-sensitive.

❑ Yes. It may contain letters or numbers, but it must be one of a finite number of values. Use menu.

❑ No. It will consist of dates and/or times. Use timestamp for store the time and date the information
was entered or updated. To store date and time both, use DateTime. Only the year, use year.

❑ No. consist only of numbers, and mathematical functions will be performed on this field.

❑ Integers from -127 to 127, use tinyint.


❑ Integers from -32768 to 32767, use smallint.

❑ Integers from -8388608 to 8388607, use mediumint.

❑ Integers from -2147483648 to 2147483647, use int.

❑ Integers from -9223372036854775808 to 9223372036854775807, use bigint.

❑ Integers from 0 to 255, use tinyint unsigned.

❑ Integers from 0 to 65535, use smallint unsigned.

❑ Integers from 0 to 16777215, use mediumint unsigned.

❑ Integers from 0 to 4294967295, use int unsigned.

❑ Integers from 0 to 18446744073709551615, use bigint unsigned.

❑ Decimals with fixed decimal places, use dec.

❑ No. It will consist of only numbers, but mathematical functions will not be performed on this field.
Use the preceding guidelines for text/number mix in the field.

Null / not null

Null tells MySQL that it is okay if nothing is stored in the field, and not null tells MySQL to require
something, anything, to be stored there.

If a field has been defined as not null and nothing is entered by the user, an error pops up.

A number zero is different from a null entry.

Indexes

MySQL uses indexes to expedite the process of searching for a particular row of information.

MySQL can jump to the approximate location of your data much more quickly. It does through the use
of indexes, also known as keys.

MySQL requires at least one index on every table, use a primary key, or unique identifier that helps
keep the data separate. This field must be “not null” and “unique”; an example would be a customer ID
number to keep your customers separate.

MySQL also provides a feature that allows a value in a field to be automatically incremented by one.

This auto_increment parameter is useful for making sure your primary key is being populated with
unique numbers.

Unique

MySQL makes sure that absolutely no duplicates exist for a particular field. Typically, this is used for only the
primary key in your table, but it can be used with any field.

Auto Increment

A field that automatically increases by one whenever a new record is added. a useful function for
assigning ID numbers.
MySQL Table Types/Storage Engines
MySQL table types/storage engines are essential features that can be used effectively for maximizing the
database's performance.

It handles create, read, and update operations for storing and managing the information in a database.

The following are various table types/storage engines supports in MySQL:


o​ ISAM
o​ MyISAM
o​ MERGE
o​ InnoDB
o​ MEMORY (HEAP)
o​ ARCHIVE
o​ BDB
o​ CSV
o​ FEDERATED

We can use the below query that determines which table types/storage engines our
MySQL server supports.
1.​ mysql> SHOW ENGINES;

The Support column value indicates whether an engine can be used or not in the current server.

A value of YES, NO, or DEFAULT shows that table type is available, not available, and available & currently
set as the default table type/storage engine.

It is essential to understand each table type's features in MySQL that enable us to decide the most appropriate among
them for our table that maximizes the performance of our databases.

Each table type in MySQL has its own advantages and disadvantages. Let us learn each table type/storage engine
and its advantages and disadvantages for choosing which one to use among them.

ISAM Table
It is abbreviated as Indexed Sequential Access Method.

This table type/storage engine has been deprecated and removed from MySQL version 5.x.

MyISAM now replaces the functionalities of this table. The size of an ISAM table is 4 GB, which requires
expensive hardware. It is not portable.

MyISAM Table
It is an extension of the ISAM storage engine.
The MyISAM table types are optimized for compression and speed and can be easily portable between system to
system.

Before version 5.5, if we do not specify the table type during table creation, it was the default storage engine. From
version 5.x,

InnoDB is used as the default table type/storage engine.

The MyISAM table size is dependent on the OS and can be up to 256 TB.

It can be compressed into read-only tables that save spaces in memory.

MyISAM table type can store 64 keys per table and contains 1024 bytes maximum key length.

The MyISAM tables work very fast, but they are not transaction-safe.

Advantages of MyISAM

If you are new, it will be best to start with MyISAM because it is simple to design and create.

It is faster than other storage engines in general conditions.

It provides full-text indexing/searching.

Disadvantages of MyISAM

MyISAM tables are not transactions-safe.

It has poor data integrity and crash recovery.

When we lock the entire table, in that case, MyISAM is slower than InnoDB.

InnoDB Table

​ The InnoDB tables in MySQL fully support transaction-safe storage engine with ACID-compliant.

​ It is the first table type that supports foreign keys.

​ The InnoDB tables also provide optimal performance.

​ Its size can be up to 64TB.

​ InnoDB tables are also portable between systems to systems similar to MyISAM.

​ InnoDB tables can also be checked and repairs by MySQL whenever necessary.

Advantages of InnoDB

InnoDB provides optimal performance while processing a large amount of data.

InnoDB tables arrange our data on the disk based on the primary key.

Disadvantages of InnoDB

InnoDB tables take more space on disk in comparison with MyISAM.

MERGE Table

MERGE table is also known as MRG_MyISAM.

This table combines multiple MyISAM tables with a similar structure (identical column and index information with
the same order) into a single table.

This table uses indexes of the component tables because it does not have its own indexes.

When we join multiple tables, it can also be used to speed up the database's performance.

We can perform only INSERT, SELECT, DELETE, and UPDATE operations on the MERGE tables.

If we use the DROP TABLE query in this storage engine, MySQL only removed the MERGE specification, and the
underlying tables cannot be affected.
Advantages of MERGE

The main advantage of this table is to remove the size limitation from MyISAM tables.

It performs more efficient searches and repairs.

It manages the set of log tables easily.

Disadvantages of MERGE

MySQL allows us to use only identical (similar structure) MyISAM tables for the MERGE table.

It cannot support all MyISAM features, such as we cannot create FULLTEXT indexes on MERGE tables.

It reads indexes slower.

Memory Table

The memory table type/storage engine creates tables, which will be stored in our memory.

It is also known as HEAP before MySQL version 4.1. This table type is faster than MyISAM because it uses hash
indexes that retrieve results faster.

We already know that data stored in memory can be crashed due to power issues or hardware failure. Therefore, we
can only use this table as temporary work areas or read-only caches for data pulled from other tables. Hence, the
memory/heap tables will be lost whenever the MySQL server halts or restarts. The memory/heap table's data life
depends on the uptime of the database server.

Advantages of Memory

The main advantage of this table type is its speed, which is very fast. It is because it uses hash indexing that retrieves
results faster.

Disadvantages of Memory

It is not a good idea to use the MEMORY storage for the long term because the data would be lost easily as soon as
the power failure or hardware crash.

CSV Table

The CSV table type/storage engine stores data in comma-separated values in a file.

It provides a convenient way to migrate data into many different software packages, such as spreadsheet
software.

This table type is not as good as a general database engine; however, it enables us to exchange our data most
effectively and easily. In addition, it will scan the whole table during the read operation.

Advantages of CSV

This table type/storage engine is advantageous when we need to export complex data from one application to a CSV
file and then import it into another application.

Disadvantages of CSV

It is not good to store a large volume of data or larger data types like BLOB, although such types are supported.

It makes data retrieval slow because there is no indexing.

FEDERATED Table

The FEDERATED table type/storage engine supports MySQL from version 5.03 that allows access data from a
remote MySQL server without using the cluster/replication technology. The federated storage engine located in local
storage does not store any data. If we will query data from a federated table stored in local memory, MySQL
automatically pulled data from the remote federated tables. It is to note that it's a way for a server, not for a client,
for accessing a remote database. It is an effective way to combine data from more than one host or copy data from
remote databases into local tables without using the data import and export method.

ARCHIVE Table

This table type/storage engine allows us to store a large volume of data in a compressed format to save disk space
and cannot be modified. Thus, it is the perfect storage engine to store log data that is no longer in active use, such
as the old invoice or sales data. It compresses the data during the insertion and can decompress it using
the Zlib library.

The archive tables only support INSERT and SELECT queries. It does not support most of the data types, such as
index data type, without which we need to scan a full table for reading rows.

Since it stored the information in a compressed format and if we want to read the table, we first need to decompress
the information. This process will take time to perform complex searches and retrievals. Therefore, if we have to
perform a large number of queries in these tables, it is beneficial to use another table such as MyISAM.

BDB Table

BDB stands for the Berkeley DB engine, which is developed by SleepyCat software. It is similar to InnoDB in the
transaction-safe. It is based on the hash storage mechanism that makes the recovery of information very quickly. It
supports page-level locking, but the data file is not portable.

MySQL Table Types/Storage Engines


MySQL table types/storage engines are essential features that can be used effectively for maximizing the
database's performance. It handles create, read, and update operations for storing and managing the
information in a database. In this tutorial, we are going to understand various storage engines or table types
used in MySQL.

The following are various table types/storage engines supports in MySQL:

o​ ISAM
o​ MyISAM
o​ MERGE
o​ InnoDB
o​ MEMORY (HEAP)
o​ ARCHIVE
o​ BDB
o​ CSV
o​ FEDERATED

We can use the below query that determines which table types/storage engines our MySQL server supports.

1.​ mysql> SHOW ENGINES;


The Support column value indicates whether an engine can be used or not in the current server. A value
of YES, NO, or DEFAULT shows that table type is available, not available, and available & currently set as the
default table type/storage engine.

It is essential to understand each table type's features in MySQL that enable us to decide the most
appropriate among them for our table that maximizes the performance of our databases. Each table type in
MySQL has its own advantages and disadvantages. Let us learn each table type/storage engine and its
advantages and disadvantages for choosing which one to use among them.

ISAM Table
It is abbreviated as Indexed Sequential Access Method. This table type/storage engine has been deprecated
and removed from MySQL version 5.x. MyISAM now replaces the functionalities of this table. The size of an
ISAM table is 4 GB, which requires expensive hardware. It is not portable.
MyISAM Table
It is an extension of the ISAM storage engine. The MyISAM table types are optimized for compression and
speed and can be easily portable between system to system. Before version 5.5, if we do not specify the
table type during table creation, it was the default storage engine. From version 5.x, InnoDB is used as the
default table type/storage engine.

The MyISAM table size is dependent on the OS and can be up to 256 TB. It can be compressed
into read-only tables that save spaces in memory. MyISAM table type can store 64 keys per table and
contains 1024 bytes maximum key length. The MyISAM tables work very fast, but they are not
transaction-safe.

Advantages of MyISAM

o​ If you are new, it will be best to start with MyISAM because it is simple to design and create.
o​ It is faster than other storage engines in general conditions.
o​ It provides full-text indexing/searching.

Disadvantages of MyISAM

o​ MyISAM tables are not transactions-safe.


o​ It has poor data integrity and crash recovery.
o​ When we lock the entire table, in that case, MyISAM is slower than InnoDB.

InnoDB Table
The InnoDB tables in MySQL fully support transaction-safe storage engine with ACID-compliant. It is the first
table type that supports foreign keys. The InnoDB tables also provide optimal performance. Its size can be up
to 64TB. InnoDB tables are also portable between systems to systems similar to MyISAM. InnoDB tables can
also be checked and repairs by MySQL whenever necessary.

Advantages of InnoDB

o​ InnoDB provides optimal performance while processing a large amount of data.


o​ InnoDB tables arrange our data on the disk based on the primary key.

Disadvantages of InnoDB

o​ InnoDB tables take more space on disk in comparison with MyISAM.

MERGE Table
MERGE table is also known as MRG_MyISAM. This table combines multiple MyISAM tables with a similar
structure (identical column and index information with the same order) into a single table. This table uses
indexes of the component tables because it does not have its own indexes. When we join multiple tables, it
can also be used to speed up the database's performance. We can perform only INSERT, SELECT, DELETE,
and UPDATE operations on the MERGE tables. If we use the DROP TABLE query in this storage engine,
MySQL only removed the MERGE specification, and the underlying tables cannot be affected.

Advantages of MERGE

o​ The main advantage of this table is to remove the size limitation from MyISAM tables.
o​ It performs more efficient searches and repairs.
o​ It manages the set of log tables easily.

Disadvantages of MERGE

o​ MySQL allows us to use only identical (similar structure) MyISAM tables for the MERGE table.
o​ It cannot support all MyISAM features, such as we cannot create FULLTEXT indexes on MERGE
tables.
o​ It reads indexes slower.

Memory Table
The memory table type/storage engine creates tables, which will be stored in our memory. It is also known
as HEAP before MySQL version 4.1. This table type is faster than MyISAM because it uses hash indexes that
retrieve results faster. We already know that data stored in memory can be crashed due to power issues or
hardware failure. Therefore, we can only use this table as temporary work areas or read-only caches for
data pulled from other tables. Hence, the memory/heap tables will be lost whenever the MySQL server halts
or restarts. The memory/heap table's data life depends on the uptime of the database server.

Advantages of Memory

The main advantage of this table type is its speed, which is very fast. It is because it uses hash indexing that
retrieves results faster.

Disadvantages of Memory

It is not a good idea to use the MEMORY storage for the long term because the data would be lost easily as
soon as the power failure or hardware crash.

CSV Table
The CSV table type/storage engine stores data in comma-separated values in a file. It provides a convenient
way to migrate data into many different software packages, such as spreadsheet software. This table type is
not as good as a general database engine; however, it enables us to exchange our data most effectively and
easily. In addition, it will scan the whole table during the read operation.

Advantages of CSV

This table type/storage engine is advantageous when we need to export complex data from one application
to a CSV file and then import it into another application.

Disadvantages of CSV

o​ It is not good to store a large volume of data or larger data types like BLOB, although such types are
supported.
o​ It makes data retrieval slow because there is no indexing.

FEDERATED Table
The FEDERATED table type/storage engine supports MySQL from version 5.03 that allows access data from
a remote MySQL server without using the cluster/replication technology. The federated storage engine
located in local storage does not store any data. If we will query data from a federated table stored in local
memory, MySQL automatically pulled data from the remote federated tables. It is to note that it's a way for a
server, not for a client, for accessing a remote database. It is an effective way to combine data from more
than one host or copy data from remote databases into local tables without using the data import and export
method.

ARCHIVE Table
This table type/storage engine allows us to store a large volume of data in a compressed format to save disk
space and cannot be modified. Thus, it is the perfect storage engine to store log data that is no longer in
active use, such as the old invoice or sales data. It compresses the data during the insertion and can
decompress it using the Zlib library.

The archive tables only support INSERT and SELECT queries. It does not support most of the data types, such
as index data type, without which we need to scan a full table for reading rows.

Since it stored the information in a compressed format and if we want to read the table, we first need to
decompress the information. This process will take time to perform complex searches and retrievals.
Therefore, if we have to perform a large number of queries in these tables, it is beneficial to use another table
such as MyISAM.

BDB Table
BDB stands for the Berkeley DB engine, which is developed by SleepyCat software. It is similar to InnoDB in
the transaction-safe. It is based on the hash storage mechanism that makes the recovery of information very
quickly. It supports page-level locking, but the data file is not portable.

Basic MySQL Query Commands


The basic commands are listed below.

1. SELECT: This statement used to retrieve the data from the tables and views.
Syntax:SELECT * FROM [TABLE NAME];

Example:SELECT * FROM EMPLOYEE;

2. SELECT DISTINCT: This statement used to retrieve the distinct data from the table and

view.

Syntax:SELECT DISTINCT [COLUMN NAME] FROM [TABLE NAME];

Example:SELECT DISTINCT EMP_NAME FROM EMPLOYEE;

3. WHERE: This MySQL Query command is used to filter the data for specific value

Syntax:SELECT * FROM [TABLE NAME] WHERE [CONDITION];

Example:SELECT * FROM EMPLOYEE WHERE EMP_ID=200;

4. AND: This condition is used to filter the data on the basis of conditions.

Syntax:SELECT [COLUMN NAMES] FROM [TABLE NAME] WHERE [CONDITION] AND [CONDITON];

Example:SELECT EMP_NAME, FROM EMPLOYEE WHERE EMP_ID=200 AND

EMP_COUNTRY=”INDIA”;

5. OR: This MySQL Query Command combines the data from the table for the specific

condition.

Syntax:SELECT [COLUMN NAMES] FROM [TABLE NAME] WHERE TRUE OR FALSE

Example:SELECT * FROM EMPLOYEE WHERE EMP_COUNTRY=”INDIA” OR EMP_COUNTRY =”USA”;

6. IN: This operator helps in filtering the data based on a value match.

Syntax:SELECT COLUMN1, COLUMN2… FROM [TABLE NAME] WHERE [COLUMN NAME] IN

(‘val1’,’val2’);
Example:SELECT EMP_NAME, EMP_SALARY FROM EMPLOYEE WHERE EMP_COUNTRY IN

(‘INDIA’,‘USA’, ‘NZ’);

7. ORDER BY: It is used to sort the data in a particular order for a particular column in

ascending or descending order.

Syntax:SELECT COLUMN1, COLUMN2, FROM [TABLE NAME] ORDER BY Column1 desc, Column2

asc;

Example:SELECT EMP_NAME, EMP_ID FROM EMPLOYEE ORDER BY EMP_NAME desc, EMP_ID

asc;

8. LIKE: This MySQL Query Command is used to retrieve the data from the table for the

specific pattern.

Syntax:SELECT COLUMN1, COLUMN2 FROM [TABLE NAME] WHERE COLUMN1 Like’’;

Example:SELECT EMP_ID, EMP_NAME, EMP_SALARY FROM EMPLOYEE WHERE EMP_NAME

like‘SA%’;

9. BETWEEN: It is used to range the data between the two conditions.

Syntax:SELECT Column1, Column2 FROM EMPLOYEE WHERE Column3 BETWEEN val1 AND

val2;

Example:SELECT EMP_ID, EMP_NAME FROM EMPLOYEE WHERE EMP_SAL BETWEEN 2000 AND

5000;

10. IS NULL: This is used for checking the value or retrieving the data for the particular

column is null.

Syntax:SELECT Column1, Column2 FROM [TABLE NAME] Column3 IS NULL;

Example:SELECT EMP_ID, EMP_NAME FROM EMPLOYEE WHERE EMP_SAL IS NULL;


Intermediate MySQL Query Commands
The intermediate commands are listed below.

11. INSERT: This statement allows you to insert one or more rows in the table.

Syntax:INSERT INTO TABLE NAME (Column1, Column2,..) VALUES (val1, val2..);

Example:INSERT INTO EMPLOYEE (EMP_NAME, EMP_SAL) Values (‘TOM’,’3000’);

12. UPDATE: This MySQL Query command is used to update the specific table and column

for the particular record.

Syntax:UPDATE [TABLE NAME] SET COLUMN1 =’’ WHERE COLUMN2 =’’;

Example:UPDATE EMPLOYEE SET EMP_SAL=6000 WHERE EMP_ID=200;

13. DELETE: The Command is used to delete the record from the table for a particular

value.

Syntax:DELETE FROM [TABLE NAME] WHERE CONDITION;

Example:DELETE FROM EMPLOYEE WHERE EMP_ID=154;

14. INNER JOIN: It allows you to retrieve the data from two table matches in one and other

tables.

Syntax:SELECT COLUMN1, COLUMN2 FROM [TABLE 1] INNER JOIN [TABLE 2] ON Condition;

Example:SELECT EMP_NAME, EMP_COUNTRY, DEP_ID FROM EMPLOYEE EMP INNER JOIN

DEPARTMENT DEP on EMP.DEP_ID= DEP.DEP_ID;

15. LEFT JOIN: It helps you in providing the data from two or more tables and it will

retrieve all the columns from the left table and will provide the data from the right table

that matches.
Syntax:SELECT T1.C1, T2.C2 FROM TABLE T1 LEFT JOIN TABLE T2 ON T1.C1= T2.C1;

Example:SELECT E.EMP_ID, D.DEP_ID FROM EMPLOYEE E LEFT JOIN DEP D ON E.DEP_ID =

D.DEP_ID;

16. RIGHT JOIN: This MySQL Query command helps in retrieving the data from two or

more tables, taking the full records from the right table, and matches the data with the left

table to show the records.

Syntax:SELECT T1.C1, T2.C2 FROM TABLE T1 RIGHT JOIN TABLE T2 ON T1.C1= T2.C1;

Example:SELECT E.EMP_ID, D.DEP_ID FROM EMPLOYEE E RIGHT JOIN DEP D ON E.DEP_ID

= D.DEP_ID;

17. CROSS JOIN: It will provide the Cartesian product of rows of joined tables like if 10 rows

in each table it will simply multiply 10*10=100 records.

Syntax:SELECT * FROM T1 CROSS JOIN T2;

Example:SELECT * FROM EMPLOYEE EMP CROSS JOIN DEP WHERE EMP.DEP_ID= DEP.DEP_ID;

18. GROUP BY: This is used to get the data for the particular value in the combined form.

Syntax:SELECT Column1, Column2 FROM TABLE WHERE CONDITION Group by Col2;

Example:SELECT Count (*), EMP_STATUS FROM EMPLOYEE Group by EMP_STATUS;

19. UNION and UNION ALL: It’s allows you to retrieve the data of multiple queries.

Syntax:SELECT Col1, Col2 from T1 UNION SELECT Col1, Col2 FROM T2;

Example:SELECT ID FROM T1 UNION ALL SELECT ID FROM T2;

20. DROP: This statement is used for dropping the table from the database.
Syntax:DROP TABLE [TABLE NAME] Condition;

Example:DROP TABLE T1, DROP TABLE Like ‘%SA%’;

Advanced MySQL query commands


The advanced commands are listed below.

1. CTE (common table expression): These Commands are used to retrieve the data from

the tables.

Syntax:WITH CTE_NAME (Column1, Column2) AS (QUERY)

SELECT * FROM CTE_NAME;

Example:WITH EMP_INDIA AS (SELECT EMP_ID, EMP_NAME FROM EMPLOYEE WHERE

EMP_COUNTRY=’INDIA’) SELECT EMP_NAME FROM EMP_INDIA WHERE EMP_ID BETWEEN 1 AND

100;

2. SUBQUERY: It means a nested query used for retrieving the data.

Syntax:SELECT Col1, Col2 FROM TABLE T1 WHERE COL3 in (SELECT Col3 from Table T2

WHERE Condition);

Example:SELECT EMP_ID, EMP_NAME FROM EMPLOYEE WHERE EMP_SAL in (Select SAL FROM

SALARY WHERE Location=’INDIA’)

3. TRANSACTION: This is used to start, commit, and rollback the particular query.

Syntax:START TRANSACTION STATEMENTS TO PERFORM COMMIT;

4. SET: Setting auto-commit off:

Syntax:SET autocommit= OFF; Or SET autocommit= 0;

5. CREATE DATABASE: This MySQL Query command is used to create the new database.
Syntax:CREATE DATABASE DATABASE_NAME;

Syntax:SHOW CREATE DATABASE EMP_SAL_CALCULATION;

To check the database available:

Syntax:SHOW DATABASES;

6. DROP DATABASE: It is used to drop the database from the server.

Syntax:DROP DATABASE database_name; Or DROP SCHEMA database_name;

Integration of PHP with MySQL & Connection to the MySQL Database

MySQL is a highly popular database management system that can power


projects of all sizes. Its ability to handle huge volumes of data without
breaking a sweat is one of its biggest selling points. Connect MySQL with
PHP code, you can make use of one of three methodologies.

There are three types of methods in PHP to connect MySQL database


through backend:

●​ MySQL

●​ MySQLi

●​ PDO

mysql() is now obsolete because of security issues like SQL injection etc, but
the other two are being actively used.

MySQLi

MySQLi is an API used as a connector function to link the backend of the


PHP app to the MySQL database. It works just like the previous version, but
it is safer and faster, and provides a better set of functions and extensions.
MySQLi was introduced with PHP 5.0.0 and the drivers were installed in
5.3.0. The API was designed to support MySQL from version 4.1.13 to newer
ones.
PDO

PHP Data Objects (PDO) extension is a Database Abstraction Layer. It is like


an interface for the backend to interact with the MySQL database and make
changes without making any change in the PHP code. It also gives you the
freedom to work with multiple databases. The major advantage of using PDO
is that your code stays simple and portable.

1.​ Create MySQL Database at the Localhost

a.​ Create Database

b.​ Create a Folder in htdocs

c.​ Create Database Connection File In PHP

d.​ Create new php file to check your database connection

e.​ Run it

What Is phpMyAdmin?

phpMyAdmin is an open-source tool for MySQL that’s available for free. It is


fundamentally written in PHP as a versatile web application and has become
one of the foremost popular MySQL administration tools over the internet. It
supports a wide extent of operations on MySQL and MariaDB.

phpMyAdmin is a popular application for MySQL database administration.


Developers can create, update, drop, alter, delete, import, and export MySQL
database tables using this phpMyAdmin. Moreover, phpMyAdmin supports
many different operations that can be performed via the user interface.

The operations like managing databases, tables, relations, columns, indexes,


permissions, users, etc., on MySQL and MariaDB, phpMyAdmin is also used
in performing administrative-level tasks such as database creation and query
execution.

It can help you run MySQL queries, repair, optimize, check tables, and
execute other database management commands.

Create MySQL Database at the Localhost

Before you start building PHP connection to MySQL database you need to
know what PHPMyAdmin is. It’s a control panel from where you can manage
the database that you’ve created. Open your browser and go to
localhost/PHPMyAdmin or click “Admin” in XAMPP UI.

When you first installed XAMPP, it only created the username for it to be
accessed, you now have to add a password to it by yourself. For this, you
have to go to User account where the user is the same as the one shown in
this picture:

Now click Edit privileges and go to Change Admin password, type your
password there and save it. Remember this password as it will be used to
connect to your Database.
Note: It is not necessary to change the password to access databases on the
localhost. It is a good practice and that is why we have used a password.

Create Database

Now return to the homepage of PHPMyAdmin. Click the New button to create
a new database.

In the new window, name your database as per your need, I am naming it
“ practice ”. Now select Collation as utf8_general_ci, as we are using it for
learning purposes and it will handle all of our queries and data that will be
covered in this tutorial series. Now click on Create and your database will be
created.
The newly created database will be empty now, as there are no tables in it. I
will be covering that in the upcoming series where we will learn how to create
tables and insert data in it. In this tutorial, we are going to connect this
database to localhost using PHP

Create a Folder in htdocs

Now, locate the folder where you installed XAMPP and open the htdocs
folder (usually c:/xampp). Create a new folder inside c:/xampp/htdocs/ and
name it “practice” we will place web files in this folder. Why we have created
a folder in htdocs? XAMPP uses folders in htdocs to execute and run your
PHP sites.

Note: If you are using WAMP, then add your practice folder in c:/wamp/www
folder.

Create Database Connection File In PHP

Create a new PHP file and name it db_connnection.php and save it. Why am I
creating a separate database connection file? Because if you have created
multiple files in which you want to insert data or select data from the
databases, you don’t need to write the code for database connection every
time.

1.​<?php
2.​
3.​functionOpenCon()
4.​{
5.​$dbhost="localhost";
6.​$dbuser="root";
7.​$dbpass="1234";
8.​$db="example";
9.​
10.​
11.​ $conn=newmysqli($dbhost, $dbuser, $dbpass,$db)ordie("Connect
failed: %s\n". $conn-> error);
12.​
13.​
14.​ return$conn;
15.​ }
16.​
17.​ functionCloseCon($conn)
18.​ {
19.​ $conn->close();
20.​ }
21.​
22.​ ?>
Here is the explanation of the variable that we have used in our
db_connection file:

1.​ $dbhost will be the host where your server is running it is usually
localhost.

2.​ $dbuser will be the username i.e. root and $dbpass will be the
password which is the same that you used to access your
PHPMyAdmin.

3.​ $dbname will be the name of your database which we have created in
this tutorial.

You just have to include it by using PHP custom function include (include
‘connection.php’) on the top of your code and call its function and use it. It
also helps when you are moving your project location from one PC to another
and you have to change the values on the single file and all the changes will
be applied to all the other files automatically.

Create a new PHP file to check your database connection

Create a new PHP file to connect to your database. Name it index.php and
add this code in this file.

1.​<?php
2.​include'db_connection.php';
3.​
4.​$conn=OpenCon();
5.​
6.​echo"Connected Successfully";
7.​
8.​CloseCon($conn);
9.​
10.​ ?>

Run it!

Now open your browser and goto localhost/practice/index.php and you


should see this screen:

MySQL Connection
A connection is a computer science facility that allows the user to connect with the database server
software. A user can connect with the database server, whether on the same machine or remote locations.
Therefore, if we want to work with the database server to send commands and receive answers in the form
of a result set, we need connections. In this article, we are going to learn how we can connect to MySQL
Server in various ways.

MySQL Connection Types


MySQL provides various ways to connect with the database server. Once we have installed the MySQL
server, we can connect it using any of the client programs that are listed below:

1.​ Command-line client


2.​ MySQL Workbench
3.​ PHP Script.

MySQL Server Connection Using command-line client


MySQL command-line client program provides interaction with the database server in an interactive and
non-interactive mode. We can see this program in the bin directory of the MySQL's installation folder. We
can open the MySQL command prompt by navigating to the bin directory of the MySQL's installation folder
and type:

1.​ MySQL
If we find the MySQL program in the PATH, we can use the below command to connect to the MySQL
Server:

Backward Skip 10sPlay VideoForward Skip 10s


1.​ mysql -u root -p
In the syntax, the -u root indicates that we will connect to the MySQL server using the root user account
and -p instructs MySQL to ask for a password.

Next, we need to type the password for the root user account and press Enter. If everything is correct, it
should give the screen as follows:

This screen indicates that we have successfully connected with the MySQL database server, where we can
send commands and receive answers in the form of a result set.

Suppose we want to display all databases available in the current server; we can use the command as
follows:

1.​ mysql> SHOW DATABASES;


It will give the below output:
If you want to disconnect the opened MySQL database server, you need to use the exit command.

1.​ mysql> EXIT;

Connect to Database Server Using MySQL Workbench


We can connect to the MySQL database server in workbench by using the following steps:

Step 1: Launch the MySQL Workbench. We should get the following screen:

Step 2: Navigate to the menu bar, click on the 'Database' and choose Connect to Database option or press
the CTRL+U command. We can also connect with the database server by just clicking the plus (+)
button located next to the MySQL Connections. See the below image:
Step 3: After choosing any of the options, we will get the below screen:

Step 4: Fill the box to create a connection, such as connection name and username, whatever you want. By
default, the username is the root, but we can also change it with a different username in the Username
textbox. After filling all boxes, click the Store in Vault ... button to write the password for the given user
account.
Step 5: We will get a new window to write the password and click the OK button.

Step 6: After entering all the details, click on the Test Connection to test the database connectivity is
successful or not. If the connection is successful, click on the OK button.
Step 7: Again, click on the OK button for saving connection setup. After finishing all the setup, we can see this
connection under MySQL Connections for connecting to the MySQL database server. See the below output
where we have Localhost3 connection name:

Step 8: Now, we can click this newly created connection that displays the current schemas and a pane for
entering queries:

Connect to MySQL Server Using PHP Script


The simplest way to connect with the MySQL database server using the PHP script is to use
the mysql_connect() function. This function needs five parameters and returns the MySQL link identifier
when the connection becomes successful. If the connection is failed, it returns FALSE.

Syntax

The following is the syntax for MySQL connection using PHP Script:

1.​ connection mysql_connect(server, user, passwordd, new_link, client_flag);


Let us explain the mysql_connect() function parameters:

Server: It is the name of a host that runs the database server. By default, its value will be lcalhost:3306.

User: It is the name of a user who accesses the database. If we will not specify this field, it assumes the
default value that will be the name of a user that owns the server process.

Password: It is the password of a user whose database you are going to access. If we will not specify this
field, it assumes the default value that will be an empty password.
New_link: If we make a second call with the same arguments in the mysql_connect() function, MySQL does
not establish a new connection. Instead, we will get the identifier of the already opened database
connection.

Client_flags: This parameter contains a combination of the below constants:

o​ MYSQL_CLIENT_SSL: It uses SSL encryption.


o​ MYSQL_CLIENT_COMPRESS: It uses a compression protocol.
o​ MYSQL_CLIENT_IGNORE_SPACE: It provides space after function names.
o​ MYSQL_CLIENT_INTERACTIVE: It provides a timeout before closing the connection.

If we want to disconnect from the MySQL database server, we can use another PHP function
named mysql_close(). It accepts only a single parameter that will be a connection returned by the
mysql_connect() function. Its syntax is given below:

1.​ bool mysql_close ( resource $link_identifier );


If we do not specify any resource, MySQL will close the last opened database. This function returns true
when the connection is closed successfully. Otherwise returns a FALSE value.

Example

The following example explain how to connect to a MySQL server using PHP Script:

1.​ <html>
2.​ <head>
3.​ <title>MySQL Server Connection</title>
4.​ </head>
5.​ <body>
6.​ <?php
7.​ $servername = 'localhost:3306';
8.​ $username = 'javatpoint';
9.​ $dbpass = 'jtp123';
10.​ $conn = mysql_connect($servername, $username, $password);
11.​ if(! $conn ) {
12.​ die('Connection failed: ' . mysql_error());
13.​ }
14.​ echo 'Connection is successful';
15.​ mysql_close($conn);
16.​ ?>
17.​ </body>
18.​ </html>

Updating, Inserting, Deleting records in the MySQL database


We will describe about the MySQL most used statement. we would love to share with you
how insert or delete/remove single or multiple rows into MySQL database table, how to
select or update data into MySQL database table.

●​ The most commonly used statement of MySQL Select statement. MySQL SELECT
statement used to fetch data/records from database table.
●​ In the INSERT INTO statement of MySQL, you can insert single or multiple rows into
the database table.
●​ MySQL UPDATE statement, you can update the single row using the UPDATE &
WHERE clause statement at a time.
●​ The DELETE statement is used to remove/delete a specific row or multiple rows
using the MySQL DELETE & WHERE clause.

Table Of Content
●​ SELECT Statement MySQL
●​ INSERT Statement MySQL
●​ UPDATE Statement MySQL
●​ DELETE Statement MySQL

SELECT Statement MySQL


In MySQL, The SELECT statement is the most commonly used MySQL statement. You can
use the SELECT statement to fetch or get data from one or more tables within the
database. With SELECT statement of MySQL, you can fetch all fields of table or specified
fields.

Syntax
In MySQL SELECT statement syntax is :-

SELECT field1, field2 … field n


FROM Table
[WHERE conditions];

Params

●​ Fields :- It’s a database column name. You can fetch one or more fields using
SELECT statement.
●​ Table :- It’s a database table name.
●​ WHERE :- It’s a option. If You want to filter some data that time specify any
condition using the WHERE clause.

SELECT Statement Example

SELECT users.id, users.name, users.age


FROM users
WHERE status = active;

INSERT INTO Statement MySQL


In MySQL, You can use the INSERT INTO statement to insert data to your database table.
With INSERT INTO statement of MySQL, you insert single row or multiple rows into
database table.

Syntax
In MySQL INSERT INTO statement syntax is :-

INSERT INTO table_name ( field1, field2,…fieldN )


VALUES ( value1, value2,…valueN );

Params

●​ Fields :- It’s a database column name. You can insert value into in it.
●​ table_name :- It’s a database table name.
●​ Value :- It’s your column values, that you want to insert into database

INSERT INTO Statement Example


Here, we will insert single row into database table name users.

INSERT INTO users(id,name) VALUES (1, 'test');

Here, we will insert multiple rows into database table name users.

INSERT INTO users


(id, first_name, last_name)
VALUES
(5, 'wis', 'check'),
(6, 'joy', 'son'),
(7, 'kemal', 'case');

UPDATE Statement MySQL


In MySQL, You can use the UPDATE statement to update or change data to your database
table. With UPDATE statement of MySQL, you can change or modify table data by using
MySQL WHERE Clause.

Syntax
In MySQL UPDATE statement syntax is :-

UPDATE table_name SET field1=new-value1, field2=new-value2

[WHERE Clause]

Params

●​ table_name: – This is the name of a database table.


●​ Fields: – This is a database column name. Where you can update the value in it
●​ Value: – These are your column values, which you want to update in the database.
●​ WHERE: – In MySQL, where the clause is used to update specific rows in a table.

UPDATE Statement Example


Here, we will update data into database table using UPDATE AND WHERE Clause
statement of MySQL.

UPDATE users
SET first_name = 'Michel'
WHERE id = 501;
DELETE Statement MySQL
In MySQL, You can use the DELETE statement to delete/remove all the data from database
table.​
You can delete/remove records single data from the databse table on the basis of
conditions.

Syntax
In MySQL DELETE statement syntax is :-

DELETE FROM table_name;

OR

DELETE FROM table_name


[WHERE Clause];

Params

●​ table_name: – This is the name of a database table.


●​ WHERE: – In MySQL, where clause is used to delete specific rows in a database
table.

DELETE Statement Example


Here, we will delete/remove data into database table using DELETE AND WHERE Clause
statement of MySQL.

DELETE FROM users


WHERE id = 15;

DELETE All Record From Table Example


In MySQL, You can use the following syntax for delete all records from databse table.

DELETE FROM users;

What Is cPanel? Pros and Cons + How to Use It


cPanel is one of the most popular control panels among web developers and hosting
companies. It is typically paired with WHM (Web Host Manager) – both components work
hand-in-hand, with each playing separate roles. Web Host Manager provides administrative
control over the server. In addition to server configurations, WHM creates multiple accounts
and manages more than one website.
Furthermore, the cPanel dashboard provides various web files, MySQL, statistics, data
tracking, and SEO features. It is no wonder that cPanel is one of the most popular control
panels among web developers and hosting companies.
To specify, when a hosting provider manages a server with WHM and creates cPanel
accounts for their customers, this practice is known as cPanel hosting.
If you want to know more about cPanel hosting, keep reading. This article will go over the
pros and cons of cPanel along with the steps of using it. In case cPanel is not suitable for
you, we will name its alternatives that are just as useful.
What Is cPanel?
cPanel is a Linux-based control panel used to conveniently manage your web hosting. The
system operates similarly to a desktop application. With cPanel, you can perform actions
from a user-friendly dashboard instead of running complex commands.
What Is cPanel Hosting?
cPanel hosting is essentially Linux-based web hosting that includes an installation of
cPanel. The hosting plan provides a cPanel account to control your web hosting elements.
With that in mind, cPanel can be used in different types of hosting, including shared,
dedicated, and managed WordPress hosting.
This control panel is a good choice for beginners looking for a straightforward control panel
solution. However, just like other hosting control panels, cPanel has its benefits and
drawbacks.
Pros:

●​ User-friendly interface. The cPanel interface categorizes various features under


manageable modules, allowing users to locate them easily. The cPanel dashboard
also comes with intuitive menus and graphics for smooth navigation.
●​ Highly compatible. As one of the most popular control panels, cPanel is compatible
with several web browsers, including Google Chrome, Safari, and Mozilla Firefox.
Additionally, cPanel supports many third-party applications, including site builders
and SEO tools.
●​ Wide range of features. Requiring no advanced technical knowledge, cPanel lets
users perform complicated tasks such as creating subdomains and FTP accounts,
managing MySQL databases, and generating site backups.
●​ Automatic software installation. Not only does cPanel provide numerous features,
but it is also well-integrated with the Softaculous Apps Installer. It grants access to
more than 400 applications, including popular content management systems.
Softaculous takes care of each application during its whole lifecycle, from installation
to updates.
●​ Reliable support. The cPanel forums and blogs contain plenty of resources.
Dedicated technical manuals for both cPanel and WHM are also available. They
explain how to use and solve issues with cPanel products.
Cons:

●​ Security vulnerability. Research shows that cPanel’s two-factor authentication


(2FA) method is vulnerable to brute force attacks. To prevent this, always make sure
your cPanel version is up-to-date.
●​ Costly license. cPanel has the highest license cost compared to its competitors.
Thus, if you’re only managing a website, a cPanel hosting plan can be a cheaper
solution as the web host will lend you their cPanel license.
●​ Risk of data loss or corruption. There are times when the cPanel system
accidentally overwrites server settings and removes all data during major updates.
This happens due to a crashed or failed hard drive. In such cases, try to perform
a full disaster recovery to restore your web server.
cPanel Tutorial: How to Use cPanel
Now that you know the pros and cons of cPanel, it’s time to learn how to use it. Before
jumping into the first cPanel tutorial, we will go over the different ways to access it.
Generally, most hosts will include a direct link to the cPanel dashboard in the welcome
email. However, if there is no link attached, you can log into your cPanel account via the
browser’s address bar.
If your site address begins with HTTP, simply add :2082 at the end of the URL. For a site
address that starts with HTTPS, write :2083. For example:

●​ http://your-site-address.com:2082
●​ https://your-site-address.com:2083
Access the URL, and it should take you to the cPanel login page.

Type in your cPanel username and password and click on the Log in button. Once you’re
inside the control dashboard, you should see various modules and features.
We will explain each section along with the main functions.

Files

The Files section contains features for direct file management. From this section, you can
upload files without an FTP client, specify privacy levels, and set up a backup wizard.
Using File Manager
cPanel includes an easy-to-use file manager that works like desktop file explorer
applications – users can easily edit, remove, or add files and folders.
Clicking on the File Manager button will take you to the page that lists all of your website
files.

From there, you can start performing various actions by clicking on the respective menu
button. For example, if you want to move a file, select one and click on the Move button.
This will trigger a prompt to appear – simply fill out the new path and click on the Move
File(s) button.
Keep in mind that every file in cPanel can affect your server, so be careful when modifying
them to prevent any site errors.

Preferences

This is where you can configure the various aspects of the cPanel dashboard, such as
language, theme, and user information. The module also includes features to add a new
cPanel account and manage the password.
Storing Basic Information
One of the most important features of this section is adding your contact information. Use
the Contact Information application to store your contact information and preferences.
Start by including your email address in the provided field – the system will notify you of any
activity in your account, like reaching your mailbox and bandwidth quota.

Then navigate to the bottom of the page and check the boxes based on your contact
preferences. For example, if you want to get notified when your email address is changed,
click on the respective box.
Simply check the boxes to receive notifications about specific circumstances. Be sure to
click Save when you’re done.

Databases

If your website uses a content management system (CMS) like WordPress, it will need a
database to store all the important data and information, such as usernames, passwords,
and posts.
This section is all about managing the databases – its tasks are mostly done via MySQL
Databases and phpMyAdmin.
Create Databases and Manage MySQL Users
Click on MySQL Databases. On the New Database section, enter your desired database
username and click Create Database.

A new database will be added to the Current Databases list.

To add a new MySQL user, scroll down to the MySQL Users section. There, enter the
username and password and click Create User.
When you’re done, navigate to the Add User To Database section. Click on the dropdown
menu and choose the new user and database – this will grant the user access to the
selected database.

Once you’re done, you can start importing your files into this new database
via phpMyAdmin. To ensure reliable site performance, try optimizing your database.

Softaculous Apps Installer

Softaculous is a script library that automates the installation processes of various


applications. The most popular software includes WordPress, phpBB, Joomla, and Drupal.
Thanks to the seamless integration with cPanel, you can directly install any software right
from the dashboard.
Install Software With Softaculous
Start by selecting the script you want to install. If you can’t find the software under
the Script section, try browsing through the categories.
In this example, we will show how to install WordPress – continue by clicking on its icon.
Important! Before you install WordPress, read the requirements to make sure you have the
necessary resources.

Clicking on the Install Now button will prompt you to configure the software setup and site
settings.
Simply choose the installation URL and specify the options for your WordPress website.
Additionally, you can create an admin account, select a free WordPress theme, and
pre-install multiple plugins.

Once you’re done, click Install to start the WordPress installation process.

Software
Generally, your web hosting will set up a dedicated section for
the Softaculous Apps Installer. However, you can also find the auto-installer
under the Software section, along with other scripts and applications.
Since this section mainly deals with programming languages, such as PHP,
Ruby, and Perl, it is mostly used by advanced users.
That said, if you have a Cloudflare account, you can sign up and enable it
here.
Setting Up Cloudflare
To set up Cloudflare for your website, simply click on the Cloudflare icon
and enter your credentials to sign in.

Once you’re logged in, click on the Domains option, and you will see a list of
active websites with their DNS details.
The easiest way to set up Cloudflare is by adding the CNAME records. This
will point a subdomain to your main domain. Go ahead and click
the Provision Domain with CNAME Setup button.

This will change the status to active, enabling Cloudflare on your website.
Domains

It’s common for webmasters to use one hosting account for multiple sites.
Hence, the Domains section provides the features for all domain-related
tasks, such as managing domain names, setting up addon domains for
newly purchased domain names, and creating parked domains.
Using the DNS Zone Editor
cPanel contains Zone Editor to create, edit, and manage DNS (Domain
Name System) records. This feature performs multiple actions, from adding
an MX record to managing domain configurations.

To create an MX record, simply click on the respective button. This will open a
new page – enter the priority value in the Priority box and a fully qualified
domain name in the Destination field.
Finally, click Add An MX Record to save the changes.

Metrics

The features listed in this module work to track website statistics, from
counting the number of visitors to monitoring resource usage. These metrics
give you access to insights that can help you make decisions to improve your
website.
Viewing Traffic Statistics
Every tool provides extensive reports of your site. For instance,
the Awstats feature is integrated with the AWStats software. It reports traffic
statistics hourly, daily, or monthly.
Moreover, the software records visitors’ data, including their browser and
location information. This helps analyze their behavior and make changes to
improve performance.
To view specific information, simply find the options on the left sidebar. To
view reports on a specific timeframe, change the Reported period.

Security

Security is a big concern for every site owner, especially if you store sensitive
information such as credit card details. This module helps you keep an eye on
key security settings on your hosting account.
There are multiple features to optimize your site security, including SSH
Access to connect to your server via SSH and SSL/TLS to enable SSL
certificates for extra security. Another essential feature is the Hotlink
Protection which prevents other sites from stealing your site resources.
Configure Hotlink Protection
Hotlink protection prevents your files from being used on other sites –
preserving your bandwidth amount. To do so, open the Hotlink
Protection feature and configure the settings.
How Do I Use FileZilla And cPanel?
Create Your FTP Account
To create your FTP account in cPanel, please refer to the following article.
Creating An FTP Account In cPanel
How Do I Connect Filezilla To cPanel?
You can connect your account and access your site via FTP with Filezilla,
CoreFTP, or Cyberduck. Of course, you can use any FTP program you want,
but these are the three that cPanel provides auto-magic instant setup files for.
If you use another program, you'll need to set it up manually.
Configure Filezilla Manually

1.​ Download Filezilla and install it on your PC


2.​ Open Filezilla
3.​ Enter in your domain name or IP address for the Host field (dedicated IP
provided in the welcome email, sent when a service is purchased)
4.​ Use your cPanel login information to log in for the username and
password fields (provided in the welcome email, sent when a service is
purchased)
5.​ 21 should be automatically applied for port even if it does not show. You
can change this here if needed
6.​ Click Quickconnect

Configure Filezilla Automatically

1.​ Download Filezilla and install it


2.​ Open cPanel (please see How To Access cPanel if not familiar how)
3.​ Go to Files > FTP Accounts

1.​ Under FTP Accounts, click Configure FTP Client for the chosen FTP
account.
1.​ Click the blue FTP Configuration File button under Filezilla to download
the file.

1.​ Run the Configuration File that you just downloaded on your local PC

You might also like