SlideShare una empresa de Scribd logo
1 de 22
MySQL
Popular Open Source Database
www.PracticalCoding.inwww.PracticalCoding.in
About MySQL
➢ Ideal for both small and large applications
➢ Developed, distributed, and supported by Oracle Corporation
➢ Facebook serves some of its data using MySQL ( Follow the updates :
https://www.facebook.com/MySQLatFacebook )
➢ Facebook version of MySQL : https://github.com/facebook/mysql-5.6
➢ MySQL Customers: http://www.mysql.com/customers/industry/?id=
➢ Free to download and use
www.PracticalCoding.inwww.PracticalCoding.in
WebScaleSQL?
A collaboration among engineers from several companies that face
similar challenges in running MySQL at scale, and seek greater
performance from a database technology tailored for their needs.
Contributions from MySQL engineering teams at Facebook, Google,
LinkedIn, and Twitter
Recently, the $168B e-commerce giant Alibaba MySQL team has joined
WebScaleSQL.
http://webscalesql.org/
www.PracticalCoding.inwww.PracticalCoding.in
MySQL Customers/Users
➢ Baidu.com
➢ Facebook
➢ Flickr
➢ LinkedIn
➢ Quora (http://www.quora.com/Why-does-
Quora-use-MySQL-as-the-data-store-
instead-of-NoSQLs-such-as-Cassandra-
MongoDB-or-CouchDB )
➢ StumbleUpon
➢ Tumblr
➢ Twitter
(http://www.itnews.com.au/News/
317811,twitter-paypal-reveal-
database-performance.aspx )
➢ Vimeo
➢ Wikipedia
➢ Wordpress
➢ Yelp
➢ Youtube
Reference: http://www.mysql.com/customers/industry/?id=85
www.PracticalCoding.inwww.PracticalCoding.in
Connecting to MySQL
➢ MySQLi extension (the "i" stands for improved)
➢ PDO (PHP Data Objects)
www.PracticalCoding.inwww.PracticalCoding.in
Get started with MySQL
Let's create a password for root user :
# mysqladmin -u root password NEWPASSWORD
Changing root password:
# mysqladmin -p -u root password NEWPASSWORD1
Let’s enter the world of MySQL:
# mysql -u root -p
www.PracticalCoding.inwww.PracticalCoding.in
MySQL Statements
➢ Don't quote database, table, or column names
➢ Don't quote column types or modifiers
➢ Don't quote numerical values
➢ Quote (single or double) non-numeric values
➢ Quote file names and passwords
➢ User names are NOT quoted in GRANT or REVOKE statements, but
they are quoted in other statements.
www.PracticalCoding.inwww.PracticalCoding.in
Viewing Databases and Tables
➢# show databases;
➢# use <dbName>;
➢# show tables;
www.PracticalCoding.inwww.PracticalCoding.in
Some common MySQL operations
➢ mysql> SET PASSWORD=PASSWORD('new_password');
➢ mysql> CREATE USER 'test1'@'localhost' IDENTIFIED BY
'welcome123';
➢ mysql> GRANT ALL PRIVILEGES ON * . * TO 'test1'@'localhost';
➢ mysql> FLUSH PRIVILEGES;
➢ mysql> DROP USER ‘test1’@‘localhost’;
www.PracticalCoding.inwww.PracticalCoding.in
Let’s try REVOKE ...
List of other common possible permissions that users can enjoy :
➢ ALL PRIVILEGES- as we saw previously, this would allow a MySQL user all access to
a designated database (or if no database is selected, across the system)
➢ CREATE- allows them to create new tables or databases
➢ DROP- allows them to them to delete tables or databases
➢ DELETE- allows them to delete rows from tables
➢ INSERT- allows them to insert rows into tables
➢ SELECT- allows them to use the Select command to read through databases
➢ UPDATE- allow them to update table rows
➢ GRANT OPTION- allows them to grant or remove other users' privileges
www.PracticalCoding.inwww.PracticalCoding.in
Databases
➢ Creating Databases
mysql> CREATE DATABASE <dbName>;
➢ Deleting Databases
mysql> drop database <dbName>;
➢ Using Databases
mysql> use <dbName>;
www.PracticalCoding.inwww.PracticalCoding.in
Before we move on to tables...
Type Description
BIGINT The BIGINT data type supports integer values ranging
between -9,223,372,036,854,775,808 and
9,223,372,036,854,775,807.
BIT The BIT data type supports binary values ranging between 1
and 64 bits
FLOAT The FLOAT data type stores approximate numeric values.
For instance, defining a column as FLOAT(5,3) will store
12.4785 as 12.479, because the defined precision is 3.
INT The INT data type supports integer values ranging between -
2,147,483,648 and 2,147,483,647.
MEDIUMINT The MEDIUMINT data type supports integer values ranging
between -8,388,608 and 8,388,607.
SMALLINT The SMALLINT data type supports integer values ranging
between 32,768 and 32,767.
TINYINT The TINYINT data type supports integer values ranging
between -128 and 127
Commonly used string data types continued...
Type Description
BLOB/LONGBLOB/MEDIUMBLOB/
TINYBLOB
The BLOB, MEDIUMBLOB, TINYBLOB, and LONGBLOB types are
used to store data such as images or binary files, and store up to
65,545.
CHAR
The CHAR type stores between 0 and 255 characters. Any column
defined as a CHAR will consume all of the allotted space
regardless of the stored string size. For instance, any CHAR
column defined as CHAR(25) will require the same amount of
space (that required to store 25 characters) no matter the size of
the stored string.
TEXT/LONGTEXT/MEDIUMTEX/
TINYTEXT
The TEXT, LONGTEXT, MEDIUM, and TINYTEXT types store up to
65,534, 4,294,967,295, 16,777,215, and 255 characters, respectively.
VARCHAR
The VARCHAR type stores up to 65,535 characters. Unlike CHAR,
each VARCHAR instance requires only the space required to store
the provided string, plus one or two additional bytes depending
on the string length.
www.PracticalCoding.in
Date and time types...
Type Description
DATE
The DATE type represents dates in the format ’YYYY-MM-DD’, and has
a range of ’1000-01-01’ to ’9999-12-31’.
DATETIME
The DATETIME type represents values containing both a date and a
corresponding time in the format ’YYYY-MM-DD HH:MM:SS’. It has a
range of ’1000-01-01 00:00:00’ to ’9999-12-31 23:59:59’
TIME The TIME type represents temporal values in the format ’HH:MM:SS’,
ranging from ’-838:59-59’ to ’838:59:59’
TIMESTAMP
Like DATETIME, the TIMESTAMP type represents values containing
both a date and time, and sports a format identical to DATETIME. Its
range is ’1970-01-01 00:00:01’ UTC to ’2038-01-09 03:14:07’ UTC. The
TIMESTAMP differs from other data types in that it can be
automatically assigned the current date/time and automatically
updated at INSERT and UPDATE time.
YEAR
The YEAR type represents years, and supports a two- (’YY’) and four-
digit format (’YYYY’). The two-digit format supports a range of 70
(1970) to 69 (2069). The four-digit format supports a range of 1901 to
2155.
www.PracticalCoding.in
Creating,Describing and Deleting Tables
➢ Creating tables
➢ Deleting tables
➢ Describing tables
www.PracticalCoding.inwww.PracticalCoding.in
Inserting data into Tables
INSERT INTO table_name (column1, column2, column3,...) VALUES
(value1, value2, value3,...)
mysql> INSERT INTO SiteUsers (firstname, lastname, email)
VALUES ('Arvind', 'Gandhi', 'arvind@test.com');
mysql> INSERT INTO SiteUsers values ('','Johny', 'Doepp',
'johny@example.com','');
www.PracticalCoding.inwww.PracticalCoding.in
Show table data
-- List all the rows of the specified columns
SELECT column1Name, column2Name, ... FROM tableName
SELECT * | column1Name AS alias1, ..., columnNName AS aliasN
FROM tableName
WHERE criteria
GROUP BY columnName
ORDER BY columnName ASC|DESC, ...
HAVING groupConstraints
LIMIT count | offset count
mysql> select * from SiteUsers;
mysql> select firstname from SiteUsers where id=1;
mysql> select firstname,lastname from SiteUsers where id=1;
mysql> select * from SiteUsers where firstname='john’;
mysql> select * from SiteUsers where id<2;
www.PracticalCoding.in
Altering tables
ALTER TABLE tableName ... -- Modify a table, e.g., ADD COLUMN and
DROP COLUMN
ALTER TABLE tableName ADD columnDefinition
ALTER TABLE tableName DROP columnName
ALTER TABLE tableName ADD FOREIGN KEY (columnName) REFERENCES
tableName (columnNmae)
ALTER TABLE tableName DROP FOREIGN KEY constraintName
mysql> alter table SiteUsers add column address text not null;
mysql> alter table SiteUsers drop address;
mysql> alter table SiteUsers change firstname firstname VARCHAR(60);
mysql> alter table SiteUsers modify firstname VARCHAR(100);
www.PracticalCoding.inwww.PracticalCoding.in
Alter tables continued...
ALTER COLUMN
Used to set or remove the default value for a column. Example:
ALTER TABLE MyTable ALTER COLUMN foo SET DEFAULT 'bar';
ALTER TABLE MyTable ALTER COLUMN foo DROP DEFAULT;
CHANGE COLUMN
Used to rename a column, change its datatype, or move it within the schema. Example:
ALTER TABLE MyTable CHANGE COLUMN foo bar VARCHAR(32) NOT NULL FIRST;
ALTER TABLE MyTable CHANGE COLUMN foo bar VARCHAR(32) NOT NULL AFTER baz;
MODIFY COLUMN
Used to do everything CHANGE COLUMN can, but without renaming the column.
Example:
ALTER TABLE MyTable MODIFY COLUMN foo VARCHAR(32) NOT NULL AFTER baz;
www.PracticalCoding.inwww.PracticalCoding.in
Updating tables
UPDATE tableName SET columnName = {value|NULL|DEFAULT},
... WHERE criteria
Example:
mysql> update SiteUsers set firstname = 'Amitabhny' where
id=3;
mysql> update SiteUsers set firstname =
'Amitabhny',lastname='Bachchan' where id=3;
www.PracticalCoding.inwww.PracticalCoding.in
Deleting table rows
-- Delete all rows from the table. Use with extreme care!
DELETE FROM tableName
-- Delete only row(s) that meets the criteria
DELETE FROM tableName WHERE criteria
www.PracticalCoding.inwww.PracticalCoding.in
Learn More
@
www.PracticalCoding.in

Más contenido relacionado

La actualidad más candente

La actualidad más candente (18)

Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
Mysql Ppt
Mysql PptMysql Ppt
Mysql Ppt
 
Mysql ppt
Mysql pptMysql ppt
Mysql ppt
 
MYSQL-Database
MYSQL-DatabaseMYSQL-Database
MYSQL-Database
 
SQL for interview
SQL for interviewSQL for interview
SQL for interview
 
Difference Between Sql - MySql and Oracle
Difference Between Sql - MySql and OracleDifference Between Sql - MySql and Oracle
Difference Between Sql - MySql and Oracle
 
MYSQL
MYSQLMYSQL
MYSQL
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
Introduction to (sql)
Introduction to (sql)Introduction to (sql)
Introduction to (sql)
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
Hbase
HbaseHbase
Hbase
 
PT- Oracle session01
PT- Oracle session01 PT- Oracle session01
PT- Oracle session01
 
SQL SERVER Training in Pune Slides
SQL SERVER Training in Pune SlidesSQL SERVER Training in Pune Slides
SQL SERVER Training in Pune Slides
 
BITS: Introduction to relational databases and MySQL - SQL
BITS: Introduction to relational databases and MySQL - SQLBITS: Introduction to relational databases and MySQL - SQL
BITS: Introduction to relational databases and MySQL - SQL
 
Introduction to NoSQL CassandraDB
Introduction to NoSQL CassandraDBIntroduction to NoSQL CassandraDB
Introduction to NoSQL CassandraDB
 
SQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate TableSQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate Table
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 

Destacado

Destacado (14)

Group presentation 38
Group presentation 38Group presentation 38
Group presentation 38
 
J-Query Course Presentation
J-Query Course PresentationJ-Query Course Presentation
J-Query Course Presentation
 
Javascript(2)
Javascript(2)Javascript(2)
Javascript(2)
 
J Query Presentation
J Query PresentationJ Query Presentation
J Query Presentation
 
Introduction to j_query
Introduction to j_queryIntroduction to j_query
Introduction to j_query
 
Javascript
JavascriptJavascript
Javascript
 
8 introduction to_java_script
8 introduction to_java_script8 introduction to_java_script
8 introduction to_java_script
 
Java script
Java scriptJava script
Java script
 
Java script
Java scriptJava script
Java script
 
Java script
Java scriptJava script
Java script
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Slideshare.Com Powerpoint
Slideshare.Com PowerpointSlideshare.Com Powerpoint
Slideshare.Com Powerpoint
 

Similar a Introduction to my_sql

mysqlanditsbasiccommands-150226033905-conversion-gate02.pdf
mysqlanditsbasiccommands-150226033905-conversion-gate02.pdfmysqlanditsbasiccommands-150226033905-conversion-gate02.pdf
mysqlanditsbasiccommands-150226033905-conversion-gate02.pdfpradnyamulay
 
Cassandra Tutorial | Data types | Why Cassandra for Big Data
 Cassandra Tutorial | Data types | Why Cassandra for Big Data Cassandra Tutorial | Data types | Why Cassandra for Big Data
Cassandra Tutorial | Data types | Why Cassandra for Big Datavinayiqbusiness
 
MySQL Reference Manual
MySQL Reference ManualMySQL Reference Manual
MySQL Reference Manualwebhostingguy
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2ADARSH BHATT
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowPavithSingh
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytWrushabhShirsat3
 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxhjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxEliasPetros
 
Managing user Online Training in IBM Netezza DBA Development by www.etraining...
Managing user Online Training in IBM Netezza DBA Development by www.etraining...Managing user Online Training in IBM Netezza DBA Development by www.etraining...
Managing user Online Training in IBM Netezza DBA Development by www.etraining...Ravikumar Nandigam
 
Sql Commands_Dr.R.Shalini.ppt
Sql Commands_Dr.R.Shalini.pptSql Commands_Dr.R.Shalini.ppt
Sql Commands_Dr.R.Shalini.pptDrRShaliniVISTAS
 

Similar a Introduction to my_sql (20)

mysqlanditsbasiccommands-150226033905-conversion-gate02.pdf
mysqlanditsbasiccommands-150226033905-conversion-gate02.pdfmysqlanditsbasiccommands-150226033905-conversion-gate02.pdf
mysqlanditsbasiccommands-150226033905-conversion-gate02.pdf
 
sql.pdf
sql.pdfsql.pdf
sql.pdf
 
Sah
SahSah
Sah
 
SQL - RDBMS Concepts
SQL - RDBMS ConceptsSQL - RDBMS Concepts
SQL - RDBMS Concepts
 
Sql
SqlSql
Sql
 
LECTURE NOTES.pdf
LECTURE NOTES.pdfLECTURE NOTES.pdf
LECTURE NOTES.pdf
 
LECTURE NOTES.pdf
LECTURE NOTES.pdfLECTURE NOTES.pdf
LECTURE NOTES.pdf
 
Cassandra Tutorial | Data types | Why Cassandra for Big Data
 Cassandra Tutorial | Data types | Why Cassandra for Big Data Cassandra Tutorial | Data types | Why Cassandra for Big Data
Cassandra Tutorial | Data types | Why Cassandra for Big Data
 
MySQL Reference Manual
MySQL Reference ManualMySQL Reference Manual
MySQL Reference Manual
 
Learn PHP Lacture2
Learn PHP Lacture2Learn PHP Lacture2
Learn PHP Lacture2
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
 
sql.pptx
sql.pptxsql.pptx
sql.pptx
 
unit-ii.pptx
unit-ii.pptxunit-ii.pptx
unit-ii.pptx
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
 
Mysql
MysqlMysql
Mysql
 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxhjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
 
Managing user Online Training in IBM Netezza DBA Development by www.etraining...
Managing user Online Training in IBM Netezza DBA Development by www.etraining...Managing user Online Training in IBM Netezza DBA Development by www.etraining...
Managing user Online Training in IBM Netezza DBA Development by www.etraining...
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Sql Commands_Dr.R.Shalini.ppt
Sql Commands_Dr.R.Shalini.pptSql Commands_Dr.R.Shalini.ppt
Sql Commands_Dr.R.Shalini.ppt
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 

Último

How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 

Último (20)

How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 

Introduction to my_sql

  • 1. MySQL Popular Open Source Database www.PracticalCoding.inwww.PracticalCoding.in
  • 2. About MySQL ➢ Ideal for both small and large applications ➢ Developed, distributed, and supported by Oracle Corporation ➢ Facebook serves some of its data using MySQL ( Follow the updates : https://www.facebook.com/MySQLatFacebook ) ➢ Facebook version of MySQL : https://github.com/facebook/mysql-5.6 ➢ MySQL Customers: http://www.mysql.com/customers/industry/?id= ➢ Free to download and use www.PracticalCoding.inwww.PracticalCoding.in
  • 3. WebScaleSQL? A collaboration among engineers from several companies that face similar challenges in running MySQL at scale, and seek greater performance from a database technology tailored for their needs. Contributions from MySQL engineering teams at Facebook, Google, LinkedIn, and Twitter Recently, the $168B e-commerce giant Alibaba MySQL team has joined WebScaleSQL. http://webscalesql.org/ www.PracticalCoding.inwww.PracticalCoding.in
  • 4. MySQL Customers/Users ➢ Baidu.com ➢ Facebook ➢ Flickr ➢ LinkedIn ➢ Quora (http://www.quora.com/Why-does- Quora-use-MySQL-as-the-data-store- instead-of-NoSQLs-such-as-Cassandra- MongoDB-or-CouchDB ) ➢ StumbleUpon ➢ Tumblr ➢ Twitter (http://www.itnews.com.au/News/ 317811,twitter-paypal-reveal- database-performance.aspx ) ➢ Vimeo ➢ Wikipedia ➢ Wordpress ➢ Yelp ➢ Youtube Reference: http://www.mysql.com/customers/industry/?id=85 www.PracticalCoding.inwww.PracticalCoding.in
  • 5. Connecting to MySQL ➢ MySQLi extension (the "i" stands for improved) ➢ PDO (PHP Data Objects) www.PracticalCoding.inwww.PracticalCoding.in
  • 6. Get started with MySQL Let's create a password for root user : # mysqladmin -u root password NEWPASSWORD Changing root password: # mysqladmin -p -u root password NEWPASSWORD1 Let’s enter the world of MySQL: # mysql -u root -p www.PracticalCoding.inwww.PracticalCoding.in
  • 7. MySQL Statements ➢ Don't quote database, table, or column names ➢ Don't quote column types or modifiers ➢ Don't quote numerical values ➢ Quote (single or double) non-numeric values ➢ Quote file names and passwords ➢ User names are NOT quoted in GRANT or REVOKE statements, but they are quoted in other statements. www.PracticalCoding.inwww.PracticalCoding.in
  • 8. Viewing Databases and Tables ➢# show databases; ➢# use <dbName>; ➢# show tables; www.PracticalCoding.inwww.PracticalCoding.in
  • 9. Some common MySQL operations ➢ mysql> SET PASSWORD=PASSWORD('new_password'); ➢ mysql> CREATE USER 'test1'@'localhost' IDENTIFIED BY 'welcome123'; ➢ mysql> GRANT ALL PRIVILEGES ON * . * TO 'test1'@'localhost'; ➢ mysql> FLUSH PRIVILEGES; ➢ mysql> DROP USER ‘test1’@‘localhost’; www.PracticalCoding.inwww.PracticalCoding.in
  • 10. Let’s try REVOKE ... List of other common possible permissions that users can enjoy : ➢ ALL PRIVILEGES- as we saw previously, this would allow a MySQL user all access to a designated database (or if no database is selected, across the system) ➢ CREATE- allows them to create new tables or databases ➢ DROP- allows them to them to delete tables or databases ➢ DELETE- allows them to delete rows from tables ➢ INSERT- allows them to insert rows into tables ➢ SELECT- allows them to use the Select command to read through databases ➢ UPDATE- allow them to update table rows ➢ GRANT OPTION- allows them to grant or remove other users' privileges www.PracticalCoding.inwww.PracticalCoding.in
  • 11. Databases ➢ Creating Databases mysql> CREATE DATABASE <dbName>; ➢ Deleting Databases mysql> drop database <dbName>; ➢ Using Databases mysql> use <dbName>; www.PracticalCoding.inwww.PracticalCoding.in
  • 12. Before we move on to tables... Type Description BIGINT The BIGINT data type supports integer values ranging between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807. BIT The BIT data type supports binary values ranging between 1 and 64 bits FLOAT The FLOAT data type stores approximate numeric values. For instance, defining a column as FLOAT(5,3) will store 12.4785 as 12.479, because the defined precision is 3. INT The INT data type supports integer values ranging between - 2,147,483,648 and 2,147,483,647. MEDIUMINT The MEDIUMINT data type supports integer values ranging between -8,388,608 and 8,388,607. SMALLINT The SMALLINT data type supports integer values ranging between 32,768 and 32,767. TINYINT The TINYINT data type supports integer values ranging between -128 and 127
  • 13. Commonly used string data types continued... Type Description BLOB/LONGBLOB/MEDIUMBLOB/ TINYBLOB The BLOB, MEDIUMBLOB, TINYBLOB, and LONGBLOB types are used to store data such as images or binary files, and store up to 65,545. CHAR The CHAR type stores between 0 and 255 characters. Any column defined as a CHAR will consume all of the allotted space regardless of the stored string size. For instance, any CHAR column defined as CHAR(25) will require the same amount of space (that required to store 25 characters) no matter the size of the stored string. TEXT/LONGTEXT/MEDIUMTEX/ TINYTEXT The TEXT, LONGTEXT, MEDIUM, and TINYTEXT types store up to 65,534, 4,294,967,295, 16,777,215, and 255 characters, respectively. VARCHAR The VARCHAR type stores up to 65,535 characters. Unlike CHAR, each VARCHAR instance requires only the space required to store the provided string, plus one or two additional bytes depending on the string length. www.PracticalCoding.in
  • 14. Date and time types... Type Description DATE The DATE type represents dates in the format ’YYYY-MM-DD’, and has a range of ’1000-01-01’ to ’9999-12-31’. DATETIME The DATETIME type represents values containing both a date and a corresponding time in the format ’YYYY-MM-DD HH:MM:SS’. It has a range of ’1000-01-01 00:00:00’ to ’9999-12-31 23:59:59’ TIME The TIME type represents temporal values in the format ’HH:MM:SS’, ranging from ’-838:59-59’ to ’838:59:59’ TIMESTAMP Like DATETIME, the TIMESTAMP type represents values containing both a date and time, and sports a format identical to DATETIME. Its range is ’1970-01-01 00:00:01’ UTC to ’2038-01-09 03:14:07’ UTC. The TIMESTAMP differs from other data types in that it can be automatically assigned the current date/time and automatically updated at INSERT and UPDATE time. YEAR The YEAR type represents years, and supports a two- (’YY’) and four- digit format (’YYYY’). The two-digit format supports a range of 70 (1970) to 69 (2069). The four-digit format supports a range of 1901 to 2155. www.PracticalCoding.in
  • 15. Creating,Describing and Deleting Tables ➢ Creating tables ➢ Deleting tables ➢ Describing tables www.PracticalCoding.inwww.PracticalCoding.in
  • 16. Inserting data into Tables INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...) mysql> INSERT INTO SiteUsers (firstname, lastname, email) VALUES ('Arvind', 'Gandhi', 'arvind@test.com'); mysql> INSERT INTO SiteUsers values ('','Johny', 'Doepp', 'johny@example.com',''); www.PracticalCoding.inwww.PracticalCoding.in
  • 17. Show table data -- List all the rows of the specified columns SELECT column1Name, column2Name, ... FROM tableName SELECT * | column1Name AS alias1, ..., columnNName AS aliasN FROM tableName WHERE criteria GROUP BY columnName ORDER BY columnName ASC|DESC, ... HAVING groupConstraints LIMIT count | offset count mysql> select * from SiteUsers; mysql> select firstname from SiteUsers where id=1; mysql> select firstname,lastname from SiteUsers where id=1; mysql> select * from SiteUsers where firstname='john’; mysql> select * from SiteUsers where id<2; www.PracticalCoding.in
  • 18. Altering tables ALTER TABLE tableName ... -- Modify a table, e.g., ADD COLUMN and DROP COLUMN ALTER TABLE tableName ADD columnDefinition ALTER TABLE tableName DROP columnName ALTER TABLE tableName ADD FOREIGN KEY (columnName) REFERENCES tableName (columnNmae) ALTER TABLE tableName DROP FOREIGN KEY constraintName mysql> alter table SiteUsers add column address text not null; mysql> alter table SiteUsers drop address; mysql> alter table SiteUsers change firstname firstname VARCHAR(60); mysql> alter table SiteUsers modify firstname VARCHAR(100); www.PracticalCoding.inwww.PracticalCoding.in
  • 19. Alter tables continued... ALTER COLUMN Used to set or remove the default value for a column. Example: ALTER TABLE MyTable ALTER COLUMN foo SET DEFAULT 'bar'; ALTER TABLE MyTable ALTER COLUMN foo DROP DEFAULT; CHANGE COLUMN Used to rename a column, change its datatype, or move it within the schema. Example: ALTER TABLE MyTable CHANGE COLUMN foo bar VARCHAR(32) NOT NULL FIRST; ALTER TABLE MyTable CHANGE COLUMN foo bar VARCHAR(32) NOT NULL AFTER baz; MODIFY COLUMN Used to do everything CHANGE COLUMN can, but without renaming the column. Example: ALTER TABLE MyTable MODIFY COLUMN foo VARCHAR(32) NOT NULL AFTER baz; www.PracticalCoding.inwww.PracticalCoding.in
  • 20. Updating tables UPDATE tableName SET columnName = {value|NULL|DEFAULT}, ... WHERE criteria Example: mysql> update SiteUsers set firstname = 'Amitabhny' where id=3; mysql> update SiteUsers set firstname = 'Amitabhny',lastname='Bachchan' where id=3; www.PracticalCoding.inwww.PracticalCoding.in
  • 21. Deleting table rows -- Delete all rows from the table. Use with extreme care! DELETE FROM tableName -- Delete only row(s) that meets the criteria DELETE FROM tableName WHERE criteria www.PracticalCoding.inwww.PracticalCoding.in

Notas del editor

  1. MySQLi Procedural : <?php $servername = "localhost"; $username = "username"; $password = "password"; // Create connection $conn = mysqli_connect($servername, $username, $password); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } echo "Connected successfully"; ?> PDO : <?php $servername = "localhost"; $username = "username"; $password = "password"; try { $conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected successfully"; } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); } ?>
  2. CREATE TABLE table_name ( column1 definition, column2 definition, ... columnN definition ); mysql> CREATE TABLE SiteUsers ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(30) NOT NULL, lastname VARCHAR(30) NOT NULL, email VARCHAR(50), reg_date TIMESTAMP ) mysql> create table mytable1 (id INT PRIMARY KEY AUTO_INCREMENT , firstname VARCHAR(50), lastname VARCHAR(50), email VARCHAR(100)); Query OK, 0 rows affected (0.16 sec) ----------------------------------------------------------------------------------------------- mysql> DROP TABLE SiteUsers; ----------------------------------------------------------------------------------------------- mysql> DESCRIBE SiteUsers; -----------------------------------------------------------------------------------------------
  3. mysql> select * from SiteUsers WHERE firstname LIKE 'Joh%'; mysql> select * from SiteUsers WHERE firstname LIKE '%ny'; mysql> select * from SiteUsers WHERE firstname LIKE '%mit%'; mysql> select * from SiteUsers WHERE firstname LIKE '____';