SlideShare a Scribd company logo
mysql
Contents of mysql Introduction Commands examples
Introduction to mysql MySQL is a powerful Relational Database Management System (RDBMS) which we will use to learn the basic principles of database and data manipulation using Structured Query Language (SQL) statements. SQL is a database language that is used to retrieve, insert, delete and update stored data. This is achieved by constructing conditional statements that conform to a specific syntax How does mysql works? MySQL is a database server program and as such is installed on one machine, but can 'serve' the database to a variety of locations
Mysql syntax mysql syntax: The great thing about everything you do in MySQL is that the "code" is very easy for humans to read, as opposed to harder programming languages like C or C++. Very few special characters and symbols are required to create a MySQL query,
Mysql commands CREATE DATABASE CREATE TABLE INSERT REPLACE UPDATE SELECT DELETE WHERE IN AND OR RLIKE DISTINCT VALUES SET MAX
Create table CREATE DATABASE: CREATE DATABASE database_name ; Will create a MySQL database. Example: mysql> CREATE TABLE users ( -> id INT NOT NULL AUTO_INCREMENT, -> name VARCHAR (50), -> email VARCHAR (50), -> PRIMARY KEY (id)); Table created.
Primary key The Primary Key is a type of index MySQL uses. This index can do such things as; Quickly find the rows that match a WHERE clause. Retrieve rows from other tables when performing joins. Sort or group a table if the sorting or grouping is done on a leftmost prefix of a usable key This can definitely help boost the speeds of your queries as well.
To add data Adding Data to a Table Adding your Data to a table is not that hard of a process at all. Basically you specify what table you are inserting the values into, then you go ahead and do so. The syntax is as follows; mysql> INSERT INTO users VALUES ("NULL","BlairIreland"," [email_address] "); If successful, you should get something like the following for a response; Query Ok, 1 row affected (0.05 sec)
Viewing data Viewing Data: After you add data to your table, you probably want to check it out to make sure everything went as planned. To do so, you would utilize the SELECT command. To view all data in the table, you would use something like this; mysql> SELECT * FROM users; This will give you an output like this 2 rows is set.
To select a particular row To select a particular row in this database though, you would use this sort of command; mysql> SELECT * FROM users WHERE (name="Blair Ireland"); This would give you +----+---------------+---------------------------------+ | id | name  | email  | +----+---------------+---------------------------------+ | 1  | Blair Ireland | bireland@thescripts.com  | +----+---------------+---------------------------------+
To select specific column select specific columns, like this; mysql> select name from users; +----------------+ | name  | +----------------+ | Blair Ireland  | | Mark Hardy  | +----------------+
Modifying database Modifying Database Data If you have data already in the database that needs some modifying, you would change it by utilizing the UPDATE command in mysql. Its use is something like this; mysql> UPDATE users SET email = 'webmaster@thescripts.com' -> WHERE email = " [email_address] "; This would just change all rows with email set to bireland@thescripts.com and change them to webmaster@thescripts.com. In this case though, only one entry has bireland@thescripts.com as its email, so only one entry would be changed.
Deleting data Deleting Database Data If you want to remove data in the database, you would use MySQL's DELETE command. Its use would be as follows mysql> DELETE FROM users WHERE (name="Mark Hardy"); This would delete Mark Hardy's entry in the database, leaving only Blair Ireland's entry in it.
Advanced commands: sql> CREATE TABLE users ( -> id INT NOT NULL AUTO_INCREMENT, -> name VARCHAR (50), -> email VARCHAR (50), -> PRIMARY KEY (id)); Table created.
Search command To do a general search, you would use the following syntax; mysql> SELECT * FROM test WHERE -> (name LIKE "%B%"); This will result in finding anything with the capital letter B in the column name. Notice the two %'s used. This checks for anything before or after that letter. You can use just one if you like though. You can place that % sign anywhere within the query though, as the search is based upon the placement of this character.
Order by command To use a literal wildcard character in your searches, you Order By mysql> SELECT * FROM users WHERE -> (name = "Joe%") ORDER BY id DESC; This will return all the records containing someone with the first name of Joe, and will output it from the greatest ID Number, descend until the lowest ID number is reached. The default for ORDER BY is ascending, so if you want it to go by the lowest ID number first, you would just type in ORDER BY id, or you could plug in the ASC keyword where DESC is currently. Both would give you the same result.
Logical operators mysql> CREATE TABLE users ( -> id INT NOT NULL AUTO_INCREMENT, -> name VARCHAR (50), -> email VARCHAR (50), -> PRIMARY KEY (id));
Not operator NOT (or) ! mysql> SELECT * FROM users WHERE -> (name != "Blair Ireland"); or mysql> SELECT * FROM users WHERE -> (name NOT = "Blair Ireland"); This query would return all records without Blair Ireland present as the name.
And operator AND (or) && mysql> SELECT * FROM users WHERE mysql> (name = "Blair Ireland") AND mysql> (email = "bireland@domainname.com"); or mysql> SELECT * FROM users WHERE -> (name = "Blair Ireland") && -> (email = "bireland@domainname.com"); This query would return all records with Blair Ireland present as the name, and bireland@domainname.com as the email.
Or operator mysql> SELECT * FROM test WHERE -> (name = "Blair Ireland") OR -> (email = "bireland@domainname.com"); or mysql> SELECT * FROM test WHERE -> (name = "Blair Ireland") || -> (email = "bireland@domainname.com"); This query would return all records with Blair Ireland present as the name, or records with bireland@domainname.com as the email.
Renaming and deleting an entire table Renaming a Table: mysql> ALTER TABLE users RENAME public; Deleting an entire table: To delete (or drop) an entire table, you would use the following syntax; mysql> DROP TABLE public; If you would like to drop more tables at once though, you would do this; mysql> DROP TABLE public, tests;
Remove and optimize table Remove a Column: mysql> ALTER TABLE public DROP COLUMN time; After you make these changes to the table, you may want to optimize the table afterwards (especially if you are using VARCHAR's, TEXT's or BLOB's, as this will optimize its memory allocation. You will also want to do it if you have deleted a large part of a table. During a table optimization, the original table is available to clients, however, modifying and adding to the table is stalled until optimization is complete. The syntax is: OPTIMIZE TABLE table_name_goes_here

More Related Content

PPT
Mysql
Deepa Lakshmi
 
PPTX
Chapter 5 transactions and dcl statements
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Mysql
lotlot
 
PPTX
Lab5 sub query
Balqees Al.Mubarak
 
DOC
Asp.Net The Data List Control
Ram Sagar Mourya
 
PPT
Database presentation
webhostingguy
 
DOC
70562-Dumps
Pragya Rastogi
 
PPTX
Parsing strange v3
Hal Stern
 
Chapter 5 transactions and dcl statements
baabtra.com - No. 1 supplier of quality freshers
 
Mysql
lotlot
 
Lab5 sub query
Balqees Al.Mubarak
 
Asp.Net The Data List Control
Ram Sagar Mourya
 
Database presentation
webhostingguy
 
70562-Dumps
Pragya Rastogi
 
Parsing strange v3
Hal Stern
 

What's hot (20)

PDF
SQLite in Adobe AIR
Peter Elst
 
PPT
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
PPTX
Sql server ___________session_18(stored procedures)
Ehtisham Ali
 
PPT
PHP - Getting good with MySQL part II
Firdaus Adib
 
PDF
DBD::SQLite
charsbar
 
PDF
Introduction to php database connectivity
baabtra.com - No. 1 supplier of quality freshers
 
PPT
MYSQL
ARJUN
 
PDF
PHP with MySQL
wahidullah mudaser
 
PPTX
Chapter 4 functions, views, indexing
baabtra.com - No. 1 supplier of quality freshers
 
PDF
Data Binding and Data Grid View Classes
Arvind Krishnaa
 
PPT
ASP.NET 08 - Data Binding And Representation
Randy Connolly
 
PPT
Php with MYSQL Database
Computer Hardware & Trouble shooting
 
PPTX
MySQL
Hideo Amezawa
 
PDF
WORKING WITH FILE AND PIPELINE PARAMETER BINDING
Hitesh Mohapatra
 
PDF
Table partitioning in PostgreSQL + Rails
Agnieszka Figiel
 
PPTX
Introduction to database
Pongsakorn U-chupala
 
DOC
Pl sql using_xml
Nayana Arewar
 
ZIP
Introduction to SQLite in Adobe AIR 1.5
Peter Elst
 
PDF
lab56_db
tutorialsruby
 
PPTX
Database Connectivity in PHP
Taha Malampatti
 
SQLite in Adobe AIR
Peter Elst
 
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
Sql server ___________session_18(stored procedures)
Ehtisham Ali
 
PHP - Getting good with MySQL part II
Firdaus Adib
 
DBD::SQLite
charsbar
 
Introduction to php database connectivity
baabtra.com - No. 1 supplier of quality freshers
 
MYSQL
ARJUN
 
PHP with MySQL
wahidullah mudaser
 
Chapter 4 functions, views, indexing
baabtra.com - No. 1 supplier of quality freshers
 
Data Binding and Data Grid View Classes
Arvind Krishnaa
 
ASP.NET 08 - Data Binding And Representation
Randy Connolly
 
Php with MYSQL Database
Computer Hardware & Trouble shooting
 
WORKING WITH FILE AND PIPELINE PARAMETER BINDING
Hitesh Mohapatra
 
Table partitioning in PostgreSQL + Rails
Agnieszka Figiel
 
Introduction to database
Pongsakorn U-chupala
 
Pl sql using_xml
Nayana Arewar
 
Introduction to SQLite in Adobe AIR 1.5
Peter Elst
 
lab56_db
tutorialsruby
 
Database Connectivity in PHP
Taha Malampatti
 
Ad

Viewers also liked (14)

DOCX
N this article first we will create a table in a my sql database and then we ...
Mark Daday
 
PDF
Instal·lació MySQL Server i Workbench. Creació de base de dades. Tipus de dad...
Miquel Boada Artigas
 
PPTX
1. Pengenalan Visual Basic .Net - Pemrograman I
Ifan Ok
 
PPTX
C# fundamentals Part 2
iFour Institute - Sustainable Learning
 
PDF
Seri Belajar Mandiri – Pemrograman VB.NET Untuk Pemula
Agus Kurniawan
 
PDF
BITS: Introduction to relational databases and MySQL - SQL
BITS
 
PDF
Learning VB.NET Programming Concepts
guest25d6e3
 
PPTX
Microsoft SQL Server internals & architecture
Kevin Kline
 
PDF
Insert, Edit, Delete pada VB 2010 dengan DB Mysql dan Crystal Report
Rahmat Taufiq Sigit
 
PDF
MS-SQL SERVER ARCHITECTURE
Douglas Bernardini
 
PPSX
C++ Programming Language
Mohamed Loey
 
PPTX
C++ ppt
Aneesh Gupta
 
PPTX
C++ ppt
parpan34
 
PPTX
Step by Step Installation of Microsoft SQL Server 2012
Sameh AboulDahab
 
N this article first we will create a table in a my sql database and then we ...
Mark Daday
 
Instal·lació MySQL Server i Workbench. Creació de base de dades. Tipus de dad...
Miquel Boada Artigas
 
1. Pengenalan Visual Basic .Net - Pemrograman I
Ifan Ok
 
Seri Belajar Mandiri – Pemrograman VB.NET Untuk Pemula
Agus Kurniawan
 
BITS: Introduction to relational databases and MySQL - SQL
BITS
 
Learning VB.NET Programming Concepts
guest25d6e3
 
Microsoft SQL Server internals & architecture
Kevin Kline
 
Insert, Edit, Delete pada VB 2010 dengan DB Mysql dan Crystal Report
Rahmat Taufiq Sigit
 
MS-SQL SERVER ARCHITECTURE
Douglas Bernardini
 
C++ Programming Language
Mohamed Loey
 
C++ ppt
Aneesh Gupta
 
C++ ppt
parpan34
 
Step by Step Installation of Microsoft SQL Server 2012
Sameh AboulDahab
 
Ad

Similar to Diva10 (20)

PPT
MYSQL
Ankush Jain
 
PPT
My sql presentation
Nikhil Jain
 
ODP
My sql Syntax
Reka
 
ODP
Web Developement Workshop (Oct 2009) Slides
Manish Sinha
 
PPT
My sql with querys
NIRMAL FELIX
 
ODP
My sql
Nadhi ya
 
PPT
MYSQL.ppt
webhostingguy
 
PPT
Sql 2006
Cathie101
 
PPT
SQL -PHP Tutorial
Information Technology
 
DOCX
Learning sql from w3schools
farhan516
 
PPT
Raj mysql
firstplanet
 
PPT
PHP tips by a MYSQL DBA
Amit Kumar Singh
 
ODP
Msql
ksujitha
 
PPT
MySQL
Gouthaman V
 
PPTX
Using Mysql.pptx
StephenEfange3
 
PPTX
Class 8 - Database Programming
Ahmed Swilam
 
PPT
Mysql
Rathan Raj
 
PPT
Php MySql For Beginners
Priti Solanki
 
My sql presentation
Nikhil Jain
 
My sql Syntax
Reka
 
Web Developement Workshop (Oct 2009) Slides
Manish Sinha
 
My sql with querys
NIRMAL FELIX
 
My sql
Nadhi ya
 
MYSQL.ppt
webhostingguy
 
Sql 2006
Cathie101
 
SQL -PHP Tutorial
Information Technology
 
Learning sql from w3schools
farhan516
 
Raj mysql
firstplanet
 
PHP tips by a MYSQL DBA
Amit Kumar Singh
 
Msql
ksujitha
 
Using Mysql.pptx
StephenEfange3
 
Class 8 - Database Programming
Ahmed Swilam
 
Mysql
Rathan Raj
 
Php MySql For Beginners
Priti Solanki
 

Recently uploaded (20)

PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Doc9.....................................
SofiaCollazos
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 

Diva10

  • 2. Contents of mysql Introduction Commands examples
  • 3. Introduction to mysql MySQL is a powerful Relational Database Management System (RDBMS) which we will use to learn the basic principles of database and data manipulation using Structured Query Language (SQL) statements. SQL is a database language that is used to retrieve, insert, delete and update stored data. This is achieved by constructing conditional statements that conform to a specific syntax How does mysql works? MySQL is a database server program and as such is installed on one machine, but can 'serve' the database to a variety of locations
  • 4. Mysql syntax mysql syntax: The great thing about everything you do in MySQL is that the "code" is very easy for humans to read, as opposed to harder programming languages like C or C++. Very few special characters and symbols are required to create a MySQL query,
  • 5. Mysql commands CREATE DATABASE CREATE TABLE INSERT REPLACE UPDATE SELECT DELETE WHERE IN AND OR RLIKE DISTINCT VALUES SET MAX
  • 6. Create table CREATE DATABASE: CREATE DATABASE database_name ; Will create a MySQL database. Example: mysql> CREATE TABLE users ( -> id INT NOT NULL AUTO_INCREMENT, -> name VARCHAR (50), -> email VARCHAR (50), -> PRIMARY KEY (id)); Table created.
  • 7. Primary key The Primary Key is a type of index MySQL uses. This index can do such things as; Quickly find the rows that match a WHERE clause. Retrieve rows from other tables when performing joins. Sort or group a table if the sorting or grouping is done on a leftmost prefix of a usable key This can definitely help boost the speeds of your queries as well.
  • 8. To add data Adding Data to a Table Adding your Data to a table is not that hard of a process at all. Basically you specify what table you are inserting the values into, then you go ahead and do so. The syntax is as follows; mysql> INSERT INTO users VALUES ("NULL","BlairIreland"," [email_address] "); If successful, you should get something like the following for a response; Query Ok, 1 row affected (0.05 sec)
  • 9. Viewing data Viewing Data: After you add data to your table, you probably want to check it out to make sure everything went as planned. To do so, you would utilize the SELECT command. To view all data in the table, you would use something like this; mysql> SELECT * FROM users; This will give you an output like this 2 rows is set.
  • 10. To select a particular row To select a particular row in this database though, you would use this sort of command; mysql> SELECT * FROM users WHERE (name="Blair Ireland"); This would give you +----+---------------+---------------------------------+ | id | name | email | +----+---------------+---------------------------------+ | 1 | Blair Ireland | [email protected] | +----+---------------+---------------------------------+
  • 11. To select specific column select specific columns, like this; mysql> select name from users; +----------------+ | name | +----------------+ | Blair Ireland | | Mark Hardy | +----------------+
  • 12. Modifying database Modifying Database Data If you have data already in the database that needs some modifying, you would change it by utilizing the UPDATE command in mysql. Its use is something like this; mysql> UPDATE users SET email = '[email protected]' -> WHERE email = " [email_address] "; This would just change all rows with email set to [email protected] and change them to [email protected]. In this case though, only one entry has [email protected] as its email, so only one entry would be changed.
  • 13. Deleting data Deleting Database Data If you want to remove data in the database, you would use MySQL's DELETE command. Its use would be as follows mysql> DELETE FROM users WHERE (name="Mark Hardy"); This would delete Mark Hardy's entry in the database, leaving only Blair Ireland's entry in it.
  • 14. Advanced commands: sql> CREATE TABLE users ( -> id INT NOT NULL AUTO_INCREMENT, -> name VARCHAR (50), -> email VARCHAR (50), -> PRIMARY KEY (id)); Table created.
  • 15. Search command To do a general search, you would use the following syntax; mysql> SELECT * FROM test WHERE -> (name LIKE "%B%"); This will result in finding anything with the capital letter B in the column name. Notice the two %'s used. This checks for anything before or after that letter. You can use just one if you like though. You can place that % sign anywhere within the query though, as the search is based upon the placement of this character.
  • 16. Order by command To use a literal wildcard character in your searches, you Order By mysql> SELECT * FROM users WHERE -> (name = "Joe%") ORDER BY id DESC; This will return all the records containing someone with the first name of Joe, and will output it from the greatest ID Number, descend until the lowest ID number is reached. The default for ORDER BY is ascending, so if you want it to go by the lowest ID number first, you would just type in ORDER BY id, or you could plug in the ASC keyword where DESC is currently. Both would give you the same result.
  • 17. Logical operators mysql> CREATE TABLE users ( -> id INT NOT NULL AUTO_INCREMENT, -> name VARCHAR (50), -> email VARCHAR (50), -> PRIMARY KEY (id));
  • 18. Not operator NOT (or) ! mysql> SELECT * FROM users WHERE -> (name != "Blair Ireland"); or mysql> SELECT * FROM users WHERE -> (name NOT = "Blair Ireland"); This query would return all records without Blair Ireland present as the name.
  • 19. And operator AND (or) && mysql> SELECT * FROM users WHERE mysql> (name = "Blair Ireland") AND mysql> (email = "[email protected]"); or mysql> SELECT * FROM users WHERE -> (name = "Blair Ireland") && -> (email = "[email protected]"); This query would return all records with Blair Ireland present as the name, and [email protected] as the email.
  • 20. Or operator mysql> SELECT * FROM test WHERE -> (name = "Blair Ireland") OR -> (email = "[email protected]"); or mysql> SELECT * FROM test WHERE -> (name = "Blair Ireland") || -> (email = "[email protected]"); This query would return all records with Blair Ireland present as the name, or records with [email protected] as the email.
  • 21. Renaming and deleting an entire table Renaming a Table: mysql> ALTER TABLE users RENAME public; Deleting an entire table: To delete (or drop) an entire table, you would use the following syntax; mysql> DROP TABLE public; If you would like to drop more tables at once though, you would do this; mysql> DROP TABLE public, tests;
  • 22. Remove and optimize table Remove a Column: mysql> ALTER TABLE public DROP COLUMN time; After you make these changes to the table, you may want to optimize the table afterwards (especially if you are using VARCHAR's, TEXT's or BLOB's, as this will optimize its memory allocation. You will also want to do it if you have deleted a large part of a table. During a table optimization, the original table is available to clients, however, modifying and adding to the table is stalled until optimization is complete. The syntax is: OPTIMIZE TABLE table_name_goes_here