Introduction to MySQL || MySQL Beginner Guide
Introduction: MySQL is a free and open-source relational database management system (RDBMS). A relational database management system organizes data into one or more data tables in which data types may be related to each other. These relations help structure the data. SQL(Structured Query Language) is a language that provides a facility to interact with the database, programmers use to create, modify and extract data from the relational database, as well as control user access to the database. In addition to relational database management systems, SQL like MySQL works with an operating system to implement a relational database in a computer’s storage system, manages users, allows for network access, and facilitates testing database integrity and creation of backups.
In this article we will use XAMPP Server for run MySQL
Download and install XAMPP Server
Open XAMPP Control panel and start apache and mysql server
Set class path for mysql
goto xampp installed location inside (xampp>mysql>bin) Copy path
go to This Pc > property >Advance System setting > Environment variable > path >Edit >New > paste path link >ok
Class path set successfully we are ready to work with MySQL
We can access mysql tool in two ways
- Graphical user interface (GUI)
- Using SQL (Structured Query Language)
In this article, we will use SQL to work with MySQL Database. So we are ready to run SQL commands Open command prompt and type
>mysql –u root –p (for login into MySQL default user name = ‘root’ password=‘’)
Some commands for create and get information about the database
>show databases for see all database available in our MySQL system
> create database database_name for create a new database in our MySQL System
> use database_name for use existing database in our MySQL system.
>show tables for see all tables inside the database.
>Create table and describe table For create table and see structure of table.
>inserting values into a table
- Insert single row value
- Insert multiple row values
>select command for Display all records from a table
> where for Search and display records with some conditions
>sorting record using order by
>alter command for add column and drop column
>rename table and drop table
>update table data using update.
>Delete table record using delete
>in() and not in()
>Group by for remove duplicate data
>Aggregate functions: Aggregate functions are built-in functions or a set of functions that operate on a set of values. They can do operations for any specific task for us and then return one final value.
SQL JOIN
An SQL join clause is used to combine rows from two or more tables based on a common field between them.
The most common type of join is sql inner join.
Different SQL joins
- Inner join
- Left join
- Right join
- Full join
Inner join: returns all row’s data when there is at least one match in both tables.
Left join: returns all row’s data from the left table and the matched rows from the right table.
Right join: returns all row’s data from the right table and the matched rows from the left table.
Full join: returns all row’s data where there is a match in one row of the tables.
Practical
Step 1 : create two tables
Step 2 : insert data into a table
Inner join operation :
Left join operation:
Right Join operation:
Full join operation :
SQL triggers
Triggers is a stored program executed automatically to respond to a specific event
Eg. Insert, update or delete operation occurred in a table.
Practical:
- Create table sales.
- Insert data without create trigger.
- Insert data with create trigger.
CREATE TABLE SALES
INSERT DATA INTO TABLE BEFORE CREATE TRIGGER.
INSERT DATA INTO TABLE AFTER CREATE TRIGGER.
3,148 views
Lokesh Pandey
Hi there! I'm Lokesh Pandey. I work as a Software Engineer i love computer programming, technology and love to share my knowledge. Please visit my website http://lokeshpandey.in/