SlideShare a Scribd company logo
1 of 118
Download to read offline
MySQL
Basics
Hello!
I am Dave Stokes
I am MySQL Community Manager and have been using MySQL for over 20
years.
@Stoker david.stokes @oracle.com
Slides at slideshare.net/davidmstokes and
github.com/davidmstokes/tutorials
2
MySQL is a relational database & a NoSQL JSON Document Database
• Community Edition – Free to use
• Enterprise Edition – Starts at $5K/4 core
CPU before discounts
• You MUST buy a license if you ship MYSQL
with your product
GNU Public Licenses Version 2
3
0.Data
How do ‘we’ remember
Recording information
Relational Databases
• Data is split up into tables
• Tables can have relations
• customer_id column in customer data
and order data for common operations
• Rich number of operations that can be
performed on the data
Structured query language (SQL)
• Kinda of like English (does not always make sense)
• VERBS
• SELECT to ask questions
• INSERT to add data
• DELETE to remove data
• UPDATE to, well, update data
• SELECT name, phone FROM friends WHERE name = ‘Dave’;
7
POP Quiz -- SQL Verbs
How do you pick out data?
How do you correct data?
How do you add data?
How do you remove data?
8
X
X
X
X
POP Quiz -- SQL Verbs
How do you pick out data?
How do you correct data?
How do you add data?
How do you remove data?
9
SELECT
X
X
X
POP Quiz -- SQL Verbs
How do you pick out data?
How do you correct data?
How do you add data?
How do you remove data?
10
SELECT
UPDATE
X
X
POP Quiz -- SQL Verbs
How do you pick out data?
How do you correct data?
How do you add data?
How do you remove data?
11
SELECT
UPDATE
INSERT
X
POP Quiz -- SQL Verbs
How do you pick out data?
How do you correct data?
How do you add data?
How do you remove data?
12
SELECT
UPDATE
INSERT
DELETE
How did you do?
13
Data stored in rows within a table
• Tables have rows of data
• Tables made up of columns
• Similar to a spreadsheet
Multiple tables per schema
• Database/schema often used
interchangeably in MySQL
• You can have multiple schemas
per server
14
Column A Column B
data data
data data
1.Installation
Choices - choices
Not actually installing software
If you have a copy of the MySQL server and a client program please feel
free to follow along. But there are too many variable to get everyone
up and running in the allotted time.
https://dev.mysql.com/downloads
• Linux
• Apt Repo for Debian based systems
• YUM repo for Redhat-ish systems
• Binaries
• Mac OS
• Windows
• Installer
• Binaries
• Source Code
• Docker
17
Make sure it is MySQL
• Some Linux distributions switched to MariaDB, a
fork of MySQL created when Oracle took over
MySQL and will NOT give you MySQL when you ask
for it. MariaDB is not a drop in replacement for
MySQL and lacks many features that you may want
that are in MySQL only.
18
Using the MySQL apt repo
• https://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/
• Go to the download page for the MySQL APT repository at
https://dev.mysql.com/downloads/repo/apt/
• shell> sudo dpkg -i mysql-apt-config_w.x.y-z_all.deb
• shell> sudo apt-get update
• shell> sudo apt-get install mysql-server
• shell> sudo service mysql start
19
Using the MySQL RPM repo
• Go to the download page for MySQL Yum repository at
https://dev.mysql.com/downloads/repo/yum/
• shell> sudo rpm -Uvh mysql80-community-release-el6-n.noarch.rpm
• shell> sudo yum install mysql-community-server
• shell> sudo systemctl start mysqld.service
20
Other installation notes
• Refer to the MySQL documentation at https://dev.mysql.com for help
with your installation
• The MySQL demo databases are found at
https://dev.mysql.com/doc/index-other.html
• You may want the mysql cli client (mysql), mysql shell (mysqlsh), and
MySQL Workbench => please drop by MySQL table in expo area for a
demo!!
21
2. Communicating with the MySQL server
Choices - choices
23
Most people think as the database residing on a
server somewhere in a computer room (or the cloud)
and the client as a laptop or desktop computer.
This is called the client server model of computing.
BTW databases run just fine on laptops too !
24
I recommend installing you favorite
Linux on an older laptop and using the
MySQL Repositories to learn MySQL
Starting the server
• The mysqld program (MySQL Daemon) runs in the background on your
Linux system. It normally listens on port 3306 (and the new NoSQL
service listens on port 33060) for programs wanting to communicate
with it
• The command line program to talk to the mysqld daemon is named mysql
• $ mysql –u user -p
PASSWORD: ********
25
The mysql client Example
26
mysql - cli program
-u texas00 - user
-p - ask for password
The new MySQl Shell or mysqlsh
• MySQL 8.0 has another shell named mysqlsh
• $ mysqlsh
• Features
• Command completion
• Improved help facility
• Three modes – JavaScript, Python & SQL
• Utility functions for admin work
• Check for server upgrade, JSON bulk
loader, Cluster Administration
27
mysqlsh
28
MySQL Workbench
29
3. First Data Set
Simple sample data
World data
• Used for MySQL documentation, tutorials, training, etcetera
• Out of date data but still useful for illustration purposes
• Download from https://dev.mysql.com/doc/index-other.html
• Extract the data with $gunzip world.sql.gz
•
• $mysql u root –p < world.sql
This has already been done in demo accounts
But documented for those using the notes later!
31
Explanation
• mysql –u root –p < world.sql
• mysql is the name of the cli program
• -u root tells server we want to use
the account as the user root
• -p is used if the account has a
password and the password will be
asked from you
• < world.sql the < command on the
Linux shell redirects input from the
file named world.sql into the mysql
cli program
32
The use command
• The MySQL server can support many databases (proper term is
schemas) and need to be told which one you want to use. We just
created a schema named world when we loaded data.
• $ mysql –u <account> –p
Password: ******
• mysql> USE world;
Database changed;
mysql>
33
Uppercase/Lowercase
• The MySQL server is case insensitive for commands if your operating
system is also case insensitive. For illustration SQL commands will be in
UPPERCASE and the stuff you need to type is in bold.
• $ mysql –u root –p
Password: ******
• mysql> USE world;
Database changed
• mysql> SHOW SCHEMAS;
34
So what do we have???
mysql> SHOW TABLES;
+-----------------+
| Tables_in_world |
+-----------------+
| city |
| country |
| countrylanguage |
+-----------------+
3 rows in set (0.01 sec)
mysql>
35
So what do we have???
mysql> SHOW TABLES;
+-----------------+
| Tables_in_world |
+-----------------+
| city |
| country |
| countrylanguage |
+-----------------+
3 rows in set (0.01 sec)
mysql>
We have three tables –
city, country, and
countrylanguage – in
our schema that can be
queried (ask for
information) for data.
36
QUICK quiz
In a relational database,
the data is organized within _________
and the data is kept in _______
37
QUICK quiz
In a relational database,
the data is organized within SCHEMAS (or databases)
and the data is kept in TABLES
38
4.Structured Query Language
How to ask a database questions
Entity Relationship Map of world schema
40
the city and countrycode tables have been set up with a CountryCode column to relate to the
code column in the countrytable’s
41
SQL or structured query language
• Designed in the 1970s
• Minimize data duplication
• Set theory and relational calculus
• When disks and memory were EXPENSIVE
• Still used today extensively
• Divided into two parts
• Data Definition Language or DDL
• What the data looks like (Integer, Text, JSON, Geometry, …)
• Data Manipulation Language
• Looking at the data or DML
42
The basic commands -> Think verbs (action words)
• SELECT
• Get data from a table
• INSERT
• Put data into the table
• UPDATE
• Change data in a table
• DELETE
• Remove data in a table
43
We covered
these ‘verbs’
earlier and they
are the core of
most queries
that you will ever
write.
Our First query
mysql> SELECT * FROM city LIMIT 1;
• SELECT – ask server for data
• * - Wildcard for all columns in a row of data
• FROM city - the name of the table we want to use
• (case must match)
• LIMIT 1 – We want a maximum of one row of data
• ; - Tells the server we are done with this command and it can be run.
44
Wildcards:
* = all columns in a table
% = Matches 1 or more characters
%name matches
first_name and last_name
45
Our First query
mysql> SELECT * FROM city LIMIT 1;
+----+-------+-------------+----------+------------+
| ID | Name | CountryCode | District | Population |
+----+-------+-------------+----------+------------+
| 1 | Kabul | AFG | Kabol | 1780000 |
+----+-------+-------------+----------+------------+
1 row in set (0.25 sec)
mysql>
46
Our First query
mysql> SELECT * FROM city LIMIT 1;
+----+-------+-------------+----------+------------+
| ID | Name | CountryCode | District | Population |
+----+-------+-------------+----------+------------+
| 1 | Kabul | AFG | Kabol | 1780000 |
+----+-------+-------------+----------+------------+
1 row in set (0.25 sec)
mysql>
The first record has the fields ID,
Name, CountryCode, District, and
Population fields for the city of Kabul
47
Our First query
mysql> SELECT * FROM city LIMIT 1;
+----+-------+-------------+----------+------------+
| ID | Name | CountryCode | District | Population |
+----+-------+-------------+----------+------------+
| 1 | Kabul | AFG | Kabol | 1780000 |
+----+-------+-------------+----------+------------+
1 row in set (0.25 sec)
mysql>
Note that some columns are numbers
only and some are alphanumeric
48
Experiment
What happens if you do not use LIMIT 1 ???
49
Experiment
What happens if you do not use LIMIT 1 ???
You get to see 4079 rows!
50
What if we want to get more specific?
• We only want the city name
• And those cities need to be in Texas
• * We will cheat and assume that somehow we know that cities in Texas
are designated by having the district column = Texas
51
The query
• mysql> SELECT name FROM city WHERE
DISTRICT = 'Texas';
52
The query –Also acceptable
• mysql> SELECT name
FROM city
WHERE DISTRICT = 'Texas';
53
Readability is VERY important
and you may prefer to break the
query up over several lines.
The query
• mysql> SELECT name FROM city WHERE
DISTRICT = 'Texas';
• SELECT name - Ask for the name column data
• FROM city - The table with the data
• WHERE - Specify constraints
• DISTRICT = ‘Texas’ - The constraint
• ; - Done with the query
54
The output
+----------------+
| name |
+----------------+
| Houston |
| Dallas |
| San Antonio |
| Austin |
| El Paso |
| Fort Worth |
| Arlington |
| Corpus Christi |
| Plano |
| Garland |
| Lubbock |
| Irving |
| Laredo |
| Amarillo |
| Brownsville |
| Pasadena |
| Grand Prairie |
| Mesquite |
| Abilene |
| Beaumont |
| Waco |
| Carrollton |
| McAllen |
| Wichita Falls |
| Midland |
| Odessa |
+----------------+
26 rows in set (0.00 sec)
55
The output
+----------------+
| name |
+----------------+
| Houston |
| Dallas |
| San Antonio |
| Austin |
| El Paso |
| Fort Worth |
| Arlington |
| Corpus Christi |
| Plano |
| Garland |
| Lubbock |
| Irving |
| Laredo |
| Amarillo |
| Brownsville |
| Pasadena |
| Grand Prairie |
| Mesquite |
| Abilene |
| Beaumont |
| Waco |
| Carrollton |
| McAllen |
| Wichita Falls |
| Midland |
| Odessa |
+----------------+
26 rows in set (0.00 sec)
26 Cities in the table with the
District = ‘Texas’!
Note they are not sorted
alphabetically *
* Usually there is no guarantee on the order
of the data returned from the server
56
WHERE -- The clause to narrow down your search
The WHERE clause in a SQL query is used to narrow down the query to the
specific record(s).
WHERE age > 21
WHERE customer_id = 26378 AND amount_due > 0
WHERE seat_row BETWEEN 2 AND 3
57
Sort by the name of the city
SELECT name
FROM city AS city_name
WHERE DISTRICT = 'Texas'
ORDER BY name;
FROM city AS
city_name tells the
server we want to
alias the name
column as refer to
is as city_name
ORDER BY name tells the
server we want the results
SORTED by the column
name
58
The output
+----------------+
| name |
+----------------+
| Abilene |
| Amarillo |
| Arlington |
| Austin |
| Beaumont |
| Brownsville |
| Carrollton |
| Corpus Christi |
| Dallas |
| El Paso |
| Fort Worth |
| Garland |
| Grand Prairie |
| Houston |
| Irving |
| Laredo |
| Lubbock |
| McAllen |
| Mesquite |
| Midland |
| Odessa |
| Pasadena |
| Plano |
| San Antonio |
| Waco |
| Wichita Falls |
+----------------+
59
Experiment
What happens if you use ORDER BY name DESC???
60
Experiment
What happens if you use ORDER BY name DESC???
The results are sorted in DESCending order, W-A
61
5. JOINing tables
How to get data from two tables (or more)
Normalizing data
Splitting up the various pieces of data into separate tables is called normalizing.
So the details on a customer are kept in a customer table and their order
information is stored in a order table.
So by using the customer ID number from the customer table, yoy can look up
their orders on the order table
SELECT * FROM orders
WHERE customer_id = 35882;
63
Relational tables
• Data is ‘normalized’ to group similar information together
• Different tables hold different sets of information
• The world schema has three tables
• City information – city
• Country information – country
• Country languages - countrylanguage
World Schema Entity Relationship Map
65
Someone has set up the
tables so that they link
through a column that is in
all three of the schemas!
Both the city and
countrylangauge tables
have columns named
CountryCode that match
up with the Code column in
the country table.
country Table
code
66
Keys between tables
countrylanguage table
countrycode
city table
countrycodeWe can cross reference data in
different tables with a column that
have a common value or values
country Table
code
= ‘USA’
(1 entry)
67
Keys between tables
countrylanguage table
countrycode = ‘USA’
(1 or more entry)
city table
countrycode = ‘USA’
(1 or more entry
If we wanted to find all the records
that mention ‘USA’ we would find one
record in the country table and one
or more entries in the city and
countryinfo tables.
JOINing two tables together
mysql> SELECT City.name,
Country.name AS Country
FROM City
JOIN Country on
(City.countrycode = Country.code)
WHERE City.name = 'Irving';
+--------+---------------+
| name | Country |
+--------+---------------+
| Irving | United States |
+--------+---------------+
1 row in set (0.00 sec)
mysql>
68
JOINing two tables together
mysql> SELECT City.name, - ask for the name from city
Country.name AS Country - ask for the name from country
FROM City ‘alias’ name as Country
JOIN Country on - match the two tables
(City.countrycode = Country.code)
WHERE City.name = 'Irving'; - for the record that matches
+--------+---------------+ the city of Irving
| name | Country |
+--------+---------------+
| Irving | United States |
+--------+---------------+
1 row in set (0.00 sec)
mysql>
69
Joins can be complex
Joins let you drill down precisely to the desired
information
70
Complex Example – you can work up to this!!
SELECT
CONCAT(customer.last_name, ', ', customer.first_name) AS customer,
address.phone,
film.title
FROM rental
INNER JOIN customer ON rental.customer_id =
customer.customer_id
INNER JOIN address ON customer.address_id = address.address_id
INNER JOIN inventory ON rental.inventory_id =
inventory.inventory_id
INNER JOIN film ON inventory.film_id = film.film_id
WHERE rental.return_date IS NULL
AND
rental_date + INTERVAL film.rental_duration DAY <
71
Write your
Own queries
72
Break number one
Fifteen minutes and no more please!!
73
6. Data Definition Language
Creating your own table
74
CREATE TABLE
mysql> CREATE TABLE foo (
-> id INT,
-> name CHAR(20)
-> );
Query OK, 0 rows affected (0.07 sec)
mysql>
CREATE TABLE
mysql> CREATE TABLE foo (
-> id INT,
-> name CHAR(20)
-> );
Query OK, 0 rows affected (0.07 sec)
mysql>
This creates a table named foo that has
two columns – id for integer data, and
name for character data.
Data types
MySQL has several types of data to meet you needs
• Numeric
• Character (usually a-zA-Z & special characters like @#&!)
• Date/Time
• String
• JSON documents
• Spatial (Graphic Information, think GPS)
• We will deal only with INT and CHAR() types (for now)
77
The next few slides are for illustration
Do not worry of these details are too much for now
I just want to show that there are many different types of data that
can be stored in a database
78
Numeric
79
Type Storage
(BYTES)
Minimum
Singed Value
Minimum
Unsigned
Value
Maximum
Signed Value
Maximum
Unsigned
Value
TINYINT 1 -128 0 127 366
SMALLINT 2 -32768 0 32767 65535
MEDIUMINT 3 -8388608 0 8388607 16777215
INT 4 -2147483648 0 2147483647 4294967295
BIGINT 8 -263 0 263-1 264-1
Textual
• CHAR(n) – Holds characters A-Za-z0-9!@#$%^&*() plus more
• VARCHAR(n) – Variable length version, extra space need to note length
• Where n is the number of character to be held.
80
CREATE TABLE - revisited
mysql> CREATE TABLE foo (
-> id INT,
-> name CHAR(10)
-> );
Query OK, 0 rows affected (0.07 sec)
mysql>
This is an example of the Data Definition Language (DDL) to
create a table. The table has two columns – id & name – to store
data.
What happens if a name is longer
than 10 characters?
82
What happens if a name is longer
than 10 characters?
83
mysql> INSERT INTO foo (id,name) VALUES (1,'ThisNameIsTooLong');
ERROR 1406 (22001): Data too long for column 'name' at row 1
INSERT INTO foo (id,name) VALUES (1,‘Dave');
• INSERT – the action we want to perform
• INTO foo – where the data is going – a TABLE named ‘foo’
• (id,name) – specify the columns to be filled
• VALUES - ‘What comes next is the data we want to store in ‘foo’
• (1,’Dave’) - the data
• ; - designates ‘end of query’
84
Let’s add some data
mysql> INSERT INTO foo (id,name) VALUES (1,'Dave');
Query OK, 1 row affected (0.01 sec)
85
Let’s add some data
mysql> INSERT INTO foo (id,name) VALUES (1,'Dave');
Query OK, 1 row affected (0.01 sec)
mysql> SELECT id, name FROM foo;
+------+------+
| id | name |
+------+------+
| 1 | Dave |
+------+------+
1 row in set (0.00 sec)
mysql>
86
Let’s add some data
mysql> INSERT INTO foo (id,name) VALUES (1,'Dave');
Query OK, 1 row affected (0.01 sec)
mysql> SELECT id, name FROM foo;
+------+------+
| id | name |
+------+------+
| 1 | Dave |
+------+------+
1 row in set (0.00 sec)
mysql>
87
EXERCISE -> Follow along
• Start your MySQL Client
• Create a schema named ‘texas’
msqyl>CREATE SCHEMA texas;
• ‘Point’ to that schema
mysql>USE texas;
• Create table from previous slide
• Input some data using your name or nickname (under 10 characters and
your lucky number
88
mysql> CREATE TABLE foo (
-> id INT,
-> name CHAR(20)
-> );
Inputting data
• INSERT INTO foo (id,name) VALUES (1,'Dave');
• INSERT INTO – The action we want to do
foo - the table we want to store data
(id,name) - the data fields
VALUES - tells server data is next
(1,'Dave'); - the actual data
89
Looking at the data we just stored
SELECT id, name FROM foo;
SELECT id FROM foo;
SELECT name FROM foo;
SELECT name, id FROM foo;
SELECT * FROM foo; -- * is a wildcard
90
What we have learned, command wise
• INSERT
• SELECT
• CREATE schema
• CREATE table
• USE schema
• SHOW SCHEMAS;
91
Modify the table by adding another column
mysql> ALTER TABLE foo ADD COLUMN zip char(5);
Query OK, 0 rows affected (0.07 sec)
Records: 0 Duplicates: 0 Warnings: 0
92
Why a char over an INTEGER?
Unless you specify most numeric values will
truncate leading zeros so it is often better to
have data such as zipcodes that WILL HAVE
leading zeros as characters to ensure you keep
those leading zeros!
Stuff Alex Trebeck Will Not EVER ask ME
93
ALTER TABLE foo ADD COLUMN zip char(5);
ALTER TABLE -- Task to be done, adding column
foo -- The name of table to ALTER
ADD COLUMN -- What action to be done
zip -- Name of the new column
char(5) -- What type of data needed
; -- ; is the end of query
94
Create a second table
And add a PRIMARY key
PEts!
What if you wanted to track pets in your neighborhood?
What information would you want to keep?
Name
Type
Owner
?
96
Normalize data
Name -- How many characters do we need to save names?
How about for the other fields?
97
Create table
CREATE TABLE pets (
);
98
Here is where we define that columns
we need to store the data we want to
keep!
Switch to demo screen
For those of you downloading the slides, this part of the tutorial is a live
demo of creating the table for the pets data.
99
Indexes also know as a key
• Without an index the entire database/file needs to be read to find the
data, pronounced ‘s l o w’!
• An index on a column lets you go directly to the matching column(s)
• By default, MySQL wants an index and will create one for you if you do
not have one
• And it usually picks one that you do not want
• And its pick may not be the best for performance
• So pick you own column or columns to index
100
101
CREATE TABLE pets2 (
id INTEGER AUTO_INCREMENT PRIMARY KEY,
name CHAR(25),
type CHAR(20),
breed CHAR(25),
owner CHAR(30),
contact CHAR(50));
Query OK, 0 rows affected (0.0618 sec)
102
CREATE TABLE pets2 (
id INTEGER AUTO_INCREMENT PRIMARY KEY,
name CHAR(25),
type CHAR(20),
breed CHAR(25),
owner CHAR(30),
contact CHAR(50));
Query OK, 0 rows affected (0.0618 sec)
103
What is PRIMARy KEY?
The primary key is the main index on a table
Hopefully this is a column that you will want/need to search on later
104
What is AUTO_INCReMENT?
Every time you add a record to a table with an autoincrement column, the
number is AUTOMATICALLY incremented
• When inserting data either do not name that column
• Or pass a NULL for the value
105
mysql>INSERT INTO pets2 (id,name)
VALUES (NULL,'Bob'), (NULL,'Kitty');
Query OK, 2 rows affected (0.0139 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> SELECT id,name FROM pets2;
+----+-------+
| id | name |
+----+-------+
| 1 | Bob |
| 2 | Kitty |
+----+-------+
2 rows in set (0.0004 sec)
The server
automatically assigned
the values for the id
column.
106
107
CREATE TABLE timekeeper (x INT AUTO_INCREMENT PRIMARY KEY,
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
dt DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
Query OK, 0 rows affected (0.0421 sec)
108
INSERT INTO timekeeper (x) VALUES (NULL);
Query OK, 1 row affected (0.0068 sec)
SELECT * FROM timekeeper;
+---+---------------------+---------------------+
| x | ts | dt |
+---+---------------------+---------------------+
| 1 | 2019-05-18 09:35:16 | 2019-05-18 09:35:16 |
+---+---------------------+---------------------+
1 row in set (0.0005 sec)
109
ALTER TABLE timekeeper ADD COLUMN y INT DEFAULT 0;
UPDATE timekeeper SET y=1 WHERE x=1;
Query OK, 1 row affected (0.0089 sec)
Rows matched: 1 Changed: 1 Warnings: 0
SELECT * FROM timekeeper;
+---+---------------------+---------------------+---+
| x | ts | dt | y |
+---+---------------------+---------------------+---+
| 1 | 2019-05-18 09:38:22 | 2019-05-18 09:38:22 | 1 |
+---+---------------------+---------------------+---+
1 row in set (0.0006 sec)
Note the time changed from 9:35 to 9:38
110
Differences between datestamp and time stamp
DATETIME values is
'1000-01-01 00:00:00.000000' to '9999-12-31
23:59:59.999999',
TIMESTAMP values is
'1970-01-01 00:00:01.000000' to '2038-01-19
03:14:07.999999'
111
General Q&A
Software
Download MySQL Server, MySQL
Workbench, and test data
Where to learn more
Books
Go to Half-Price Books and find a
book on MySQL
Or go online -> google ‘mysql intro’
And look at www.mysql.com
112
There is a big demand for
DBAs and Devs that know
Databases
A complex idea can be conveyed
with just a single still image,
namely making it possible to
absorb large amounts of data
quickly.
113
“You learn more database
concepts by ‘breaking things’ and
learning how to fix them then by
just reading the manual”
114
Some other things that novices will run into that need some extra
explanation
Data Concepts
Think: Bank taking funds from Customer A to pay Customer B
TRANSACTION
1. Does Customer A have enough funds to cover?
2. Place holds on the accounts for Customer A & Customer B to keep other
transactions from interfering with this transaction
3. Withdraw MONEY from Customer A
4. Deposit MONEY into Customer B’s account
5. Remove holds on both account
116
Transactions
Locking records
• Records are LOCKed to keep others from changing values in row
• Others will have to wait for locks to be released (called BLOCKING)
• You can lock records in many ways
• SHARED
• EXCLUSIVE
117
Thanks!
Any questions?
You can find me at @stoker david.stokes @oracle.com
Slideshare.net/davidmstokes
118

More Related Content

What's hot

Windowing Functions - Little Rock Tech Fest 2019
Windowing Functions - Little Rock Tech Fest 2019Windowing Functions - Little Rock Tech Fest 2019
Windowing Functions - Little Rock Tech Fest 2019Dave Stokes
 
Confoo 2021 - MySQL Indexes & Histograms
Confoo 2021 - MySQL Indexes & HistogramsConfoo 2021 - MySQL Indexes & Histograms
Confoo 2021 - MySQL Indexes & HistogramsDave Stokes
 
Confoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesConfoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesDave Stokes
 
Taming Big Data with Big SQL 3.0
Taming Big Data with Big SQL 3.0Taming Big Data with Big SQL 3.0
Taming Big Data with Big SQL 3.0Nicolas Morales
 
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScriptJavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScriptDave Stokes
 
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...Dave Stokes
 
Adding Value to HBase with IBM InfoSphere BigInsights and BigSQL
Adding Value to HBase with IBM InfoSphere BigInsights and BigSQLAdding Value to HBase with IBM InfoSphere BigInsights and BigSQL
Adding Value to HBase with IBM InfoSphere BigInsights and BigSQLPiotr Pruski
 
Big Data: Big SQL and HBase
Big Data:  Big SQL and HBase Big Data:  Big SQL and HBase
Big Data: Big SQL and HBase Cynthia Saracco
 
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...Dave Stokes
 
Big SQL 3.0 - Toronto Meetup -- May 2014
Big SQL 3.0 - Toronto Meetup -- May 2014Big SQL 3.0 - Toronto Meetup -- May 2014
Big SQL 3.0 - Toronto Meetup -- May 2014Nicolas Morales
 
Architecture of exadata database machine – Part II
Architecture of exadata database machine – Part IIArchitecture of exadata database machine – Part II
Architecture of exadata database machine – Part IIParesh Nayak,OCP®,Prince2®
 
Working with Databases and MySQL
Working with Databases and MySQLWorking with Databases and MySQL
Working with Databases and MySQLNicole Ryan
 
Json within a relational database
Json within a relational databaseJson within a relational database
Json within a relational databaseDave Stokes
 
Oracle 12.2 sharded database management
Oracle 12.2 sharded database managementOracle 12.2 sharded database management
Oracle 12.2 sharded database managementLeyi (Kamus) Zhang
 
Microsoft SQL Server Data Warehouses for SQL Server DBAs
Microsoft SQL Server Data Warehouses for SQL Server DBAsMicrosoft SQL Server Data Warehouses for SQL Server DBAs
Microsoft SQL Server Data Warehouses for SQL Server DBAsMark Kromer
 

What's hot (18)

Windowing Functions - Little Rock Tech Fest 2019
Windowing Functions - Little Rock Tech Fest 2019Windowing Functions - Little Rock Tech Fest 2019
Windowing Functions - Little Rock Tech Fest 2019
 
Confoo 2021 - MySQL Indexes & Histograms
Confoo 2021 - MySQL Indexes & HistogramsConfoo 2021 - MySQL Indexes & Histograms
Confoo 2021 - MySQL Indexes & Histograms
 
Confoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesConfoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New Features
 
Taming Big Data with Big SQL 3.0
Taming Big Data with Big SQL 3.0Taming Big Data with Big SQL 3.0
Taming Big Data with Big SQL 3.0
 
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScriptJavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
 
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
 
MYSQL-Database
MYSQL-DatabaseMYSQL-Database
MYSQL-Database
 
Adding Value to HBase with IBM InfoSphere BigInsights and BigSQL
Adding Value to HBase with IBM InfoSphere BigInsights and BigSQLAdding Value to HBase with IBM InfoSphere BigInsights and BigSQL
Adding Value to HBase with IBM InfoSphere BigInsights and BigSQL
 
Big Data: Big SQL and HBase
Big Data:  Big SQL and HBase Big Data:  Big SQL and HBase
Big Data: Big SQL and HBase
 
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
 
Big SQL 3.0 - Toronto Meetup -- May 2014
Big SQL 3.0 - Toronto Meetup -- May 2014Big SQL 3.0 - Toronto Meetup -- May 2014
Big SQL 3.0 - Toronto Meetup -- May 2014
 
Architecture of exadata database machine – Part II
Architecture of exadata database machine – Part IIArchitecture of exadata database machine – Part II
Architecture of exadata database machine – Part II
 
MySQL ppt
MySQL ppt MySQL ppt
MySQL ppt
 
Working with Databases and MySQL
Working with Databases and MySQLWorking with Databases and MySQL
Working with Databases and MySQL
 
Json within a relational database
Json within a relational databaseJson within a relational database
Json within a relational database
 
Oracle 12.2 sharded database management
Oracle 12.2 sharded database managementOracle 12.2 sharded database management
Oracle 12.2 sharded database management
 
Microsoft SQL Server Data Warehouses for SQL Server DBAs
Microsoft SQL Server Data Warehouses for SQL Server DBAsMicrosoft SQL Server Data Warehouses for SQL Server DBAs
Microsoft SQL Server Data Warehouses for SQL Server DBAs
 
Mysql database
Mysql databaseMysql database
Mysql database
 

Similar to MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019

xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytWrushabhShirsat3
 
Python Utilities for Managing MySQL Databases
Python Utilities for Managing MySQL DatabasesPython Utilities for Managing MySQL Databases
Python Utilities for Managing MySQL DatabasesMats Kindahl
 
MySQL Without the SQL -- Oh My! Longhorn PHP Conference
MySQL Without the SQL -- Oh My!  Longhorn PHP ConferenceMySQL Without the SQL -- Oh My!  Longhorn PHP Conference
MySQL Without the SQL -- Oh My! Longhorn PHP ConferenceDave Stokes
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsTeamstudio
 
MySQL Without the MySQL -- Oh My!
MySQL Without the MySQL -- Oh My!MySQL Without the MySQL -- Oh My!
MySQL Without the MySQL -- Oh My!Dave Stokes
 
android sqlite
android sqliteandroid sqlite
android sqliteDeepa Rani
 
Getting started into mySQL
Getting started into mySQLGetting started into mySQL
Getting started into mySQLSiddique Ibrahim
 
Drilling into Data with Apache Drill
Drilling into Data with Apache DrillDrilling into Data with Apache Drill
Drilling into Data with Apache DrillDataWorks Summit
 
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL Server
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL ServerGeek Sync I Need for Speed: In-Memory Databases in Oracle and SQL Server
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL ServerIDERA Software
 
Drilling into Data with Apache Drill
Drilling into Data with Apache DrillDrilling into Data with Apache Drill
Drilling into Data with Apache DrillMapR Technologies
 
SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptxKulbir4
 
MySQL NDB Cluster 8.0
MySQL NDB Cluster 8.0MySQL NDB Cluster 8.0
MySQL NDB Cluster 8.0Ted Wennmark
 
Aioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAiougVizagChapter
 
My sql technical reference manual
My sql technical reference manualMy sql technical reference manual
My sql technical reference manualMir Majid
 
سکوهای ابری و مدل های برنامه نویسی در ابر
سکوهای ابری و مدل های برنامه نویسی در ابرسکوهای ابری و مدل های برنامه نویسی در ابر
سکوهای ابری و مدل های برنامه نویسی در ابرdatastack
 
Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...
Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...
Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...Databricks
 

Similar to MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019 (20)

Fudcon talk.ppt
Fudcon talk.pptFudcon talk.ppt
Fudcon talk.ppt
 
unit-ii.pptx
unit-ii.pptxunit-ii.pptx
unit-ii.pptx
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
 
Python Utilities for Managing MySQL Databases
Python Utilities for Managing MySQL DatabasesPython Utilities for Managing MySQL Databases
Python Utilities for Managing MySQL Databases
 
MySQL Without the SQL -- Oh My! Longhorn PHP Conference
MySQL Without the SQL -- Oh My!  Longhorn PHP ConferenceMySQL Without the SQL -- Oh My!  Longhorn PHP Conference
MySQL Without the SQL -- Oh My! Longhorn PHP Conference
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational Controls
 
MySQL Without the MySQL -- Oh My!
MySQL Without the MySQL -- Oh My!MySQL Without the MySQL -- Oh My!
MySQL Without the MySQL -- Oh My!
 
android sqlite
android sqliteandroid sqlite
android sqlite
 
Revision
RevisionRevision
Revision
 
Getting started into mySQL
Getting started into mySQLGetting started into mySQL
Getting started into mySQL
 
Drilling into Data with Apache Drill
Drilling into Data with Apache DrillDrilling into Data with Apache Drill
Drilling into Data with Apache Drill
 
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL Server
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL ServerGeek Sync I Need for Speed: In-Memory Databases in Oracle and SQL Server
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL Server
 
Perl Programming - 04 Programming Database
Perl Programming - 04 Programming DatabasePerl Programming - 04 Programming Database
Perl Programming - 04 Programming Database
 
Drilling into Data with Apache Drill
Drilling into Data with Apache DrillDrilling into Data with Apache Drill
Drilling into Data with Apache Drill
 
SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptx
 
MySQL NDB Cluster 8.0
MySQL NDB Cluster 8.0MySQL NDB Cluster 8.0
MySQL NDB Cluster 8.0
 
Aioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_features
 
My sql technical reference manual
My sql technical reference manualMy sql technical reference manual
My sql technical reference manual
 
سکوهای ابری و مدل های برنامه نویسی در ابر
سکوهای ابری و مدل های برنامه نویسی در ابرسکوهای ابری و مدل های برنامه نویسی در ابر
سکوهای ابری و مدل های برنامه نویسی در ابر
 
Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...
Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...
Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...
 

More from Dave Stokes

Locking Down Your MySQL Database.pptx
Locking Down Your MySQL Database.pptxLocking Down Your MySQL Database.pptx
Locking Down Your MySQL Database.pptxDave Stokes
 
Linuxfest Northwest 2022 - MySQL 8.0 Nre Features
Linuxfest Northwest 2022 - MySQL 8.0 Nre FeaturesLinuxfest Northwest 2022 - MySQL 8.0 Nre Features
Linuxfest Northwest 2022 - MySQL 8.0 Nre FeaturesDave Stokes
 
MySQL Indexes and Histograms - RMOUG Training Days 2022
MySQL Indexes and Histograms - RMOUG Training Days 2022MySQL Indexes and Histograms - RMOUG Training Days 2022
MySQL Indexes and Histograms - RMOUG Training Days 2022Dave Stokes
 
Windowing Functions - Little Rock Tech fest 2019
Windowing Functions - Little Rock Tech fest 2019Windowing Functions - Little Rock Tech fest 2019
Windowing Functions - Little Rock Tech fest 2019Dave Stokes
 
The Proper Care and Feeding of MySQL Databases
The Proper Care and Feeding of MySQL DatabasesThe Proper Care and Feeding of MySQL Databases
The Proper Care and Feeding of MySQL DatabasesDave Stokes
 
MySQL Without The SQL -- Oh My! PHP[Tek] June 2018
MySQL Without The SQL -- Oh My! PHP[Tek] June 2018MySQL Without The SQL -- Oh My! PHP[Tek] June 2018
MySQL Without The SQL -- Oh My! PHP[Tek] June 2018Dave Stokes
 
Presentation Skills for Open Source Folks
Presentation Skills for Open Source FolksPresentation Skills for Open Source Folks
Presentation Skills for Open Source FolksDave Stokes
 
ConFoo MySQL Replication Evolution : From Simple to Group Replication
ConFoo  MySQL Replication Evolution : From Simple to Group ReplicationConFoo  MySQL Replication Evolution : From Simple to Group Replication
ConFoo MySQL Replication Evolution : From Simple to Group ReplicationDave Stokes
 
Advanced MySQL Query Optimizations
Advanced MySQL Query OptimizationsAdvanced MySQL Query Optimizations
Advanced MySQL Query OptimizationsDave Stokes
 
Making MySQL Agile-ish
Making MySQL Agile-ishMaking MySQL Agile-ish
Making MySQL Agile-ishDave Stokes
 
PHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHPPHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHPDave Stokes
 
MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017Dave Stokes
 
MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017Dave Stokes
 
MySQL's JSON Data Type and Document Store
MySQL's JSON Data Type and Document StoreMySQL's JSON Data Type and Document Store
MySQL's JSON Data Type and Document StoreDave Stokes
 
Five Database Mistakes and how to fix them -- Confoo Vancouver
Five Database Mistakes and how to fix them -- Confoo VancouverFive Database Mistakes and how to fix them -- Confoo Vancouver
Five Database Mistakes and how to fix them -- Confoo VancouverDave Stokes
 
MySQL Utilities -- Cool Tools For You: PHP World Nov 16 2016
MySQL Utilities -- Cool Tools For You: PHP World Nov 16 2016MySQL Utilities -- Cool Tools For You: PHP World Nov 16 2016
MySQL Utilities -- Cool Tools For You: PHP World Nov 16 2016Dave Stokes
 
Why Your Database Queries Stink -SeaGl.org November 11th, 2016
Why Your Database Queries Stink -SeaGl.org November 11th, 2016Why Your Database Queries Stink -SeaGl.org November 11th, 2016
Why Your Database Queries Stink -SeaGl.org November 11th, 2016Dave Stokes
 
All Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for NewbiesAll Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for NewbiesDave Stokes
 
MySQL as a Document Store
MySQL as a Document StoreMySQL as a Document Store
MySQL as a Document StoreDave Stokes
 
MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016Dave Stokes
 

More from Dave Stokes (20)

Locking Down Your MySQL Database.pptx
Locking Down Your MySQL Database.pptxLocking Down Your MySQL Database.pptx
Locking Down Your MySQL Database.pptx
 
Linuxfest Northwest 2022 - MySQL 8.0 Nre Features
Linuxfest Northwest 2022 - MySQL 8.0 Nre FeaturesLinuxfest Northwest 2022 - MySQL 8.0 Nre Features
Linuxfest Northwest 2022 - MySQL 8.0 Nre Features
 
MySQL Indexes and Histograms - RMOUG Training Days 2022
MySQL Indexes and Histograms - RMOUG Training Days 2022MySQL Indexes and Histograms - RMOUG Training Days 2022
MySQL Indexes and Histograms - RMOUG Training Days 2022
 
Windowing Functions - Little Rock Tech fest 2019
Windowing Functions - Little Rock Tech fest 2019Windowing Functions - Little Rock Tech fest 2019
Windowing Functions - Little Rock Tech fest 2019
 
The Proper Care and Feeding of MySQL Databases
The Proper Care and Feeding of MySQL DatabasesThe Proper Care and Feeding of MySQL Databases
The Proper Care and Feeding of MySQL Databases
 
MySQL Without The SQL -- Oh My! PHP[Tek] June 2018
MySQL Without The SQL -- Oh My! PHP[Tek] June 2018MySQL Without The SQL -- Oh My! PHP[Tek] June 2018
MySQL Without The SQL -- Oh My! PHP[Tek] June 2018
 
Presentation Skills for Open Source Folks
Presentation Skills for Open Source FolksPresentation Skills for Open Source Folks
Presentation Skills for Open Source Folks
 
ConFoo MySQL Replication Evolution : From Simple to Group Replication
ConFoo  MySQL Replication Evolution : From Simple to Group ReplicationConFoo  MySQL Replication Evolution : From Simple to Group Replication
ConFoo MySQL Replication Evolution : From Simple to Group Replication
 
Advanced MySQL Query Optimizations
Advanced MySQL Query OptimizationsAdvanced MySQL Query Optimizations
Advanced MySQL Query Optimizations
 
Making MySQL Agile-ish
Making MySQL Agile-ishMaking MySQL Agile-ish
Making MySQL Agile-ish
 
PHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHPPHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHP
 
MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017MySQL 101 PHPTek 2017
MySQL 101 PHPTek 2017
 
MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017
 
MySQL's JSON Data Type and Document Store
MySQL's JSON Data Type and Document StoreMySQL's JSON Data Type and Document Store
MySQL's JSON Data Type and Document Store
 
Five Database Mistakes and how to fix them -- Confoo Vancouver
Five Database Mistakes and how to fix them -- Confoo VancouverFive Database Mistakes and how to fix them -- Confoo Vancouver
Five Database Mistakes and how to fix them -- Confoo Vancouver
 
MySQL Utilities -- Cool Tools For You: PHP World Nov 16 2016
MySQL Utilities -- Cool Tools For You: PHP World Nov 16 2016MySQL Utilities -- Cool Tools For You: PHP World Nov 16 2016
MySQL Utilities -- Cool Tools For You: PHP World Nov 16 2016
 
Why Your Database Queries Stink -SeaGl.org November 11th, 2016
Why Your Database Queries Stink -SeaGl.org November 11th, 2016Why Your Database Queries Stink -SeaGl.org November 11th, 2016
Why Your Database Queries Stink -SeaGl.org November 11th, 2016
 
All Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for NewbiesAll Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for Newbies
 
MySQL as a Document Store
MySQL as a Document StoreMySQL as a Document Store
MySQL as a Document Store
 
MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016
 

Recently uploaded

Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.soniya singh
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.soniya singh
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445ruhi
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxellan12
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Servicegwenoracqe6
 
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663Call Girls Mumbai
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableSeo
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...SofiyaSharma5
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...singhpriety023
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...tanu pandey
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024APNIC
 
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.soniya singh
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...Neha Pandey
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Servicesexy call girls service in goa
 

Recently uploaded (20)

Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
 
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptxAWS Community DAY Albertini-Ellan Cloud Security (1).pptx
AWS Community DAY Albertini-Ellan Cloud Security (1).pptx
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
 
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
 
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024
 
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 

MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019

  • 2. Hello! I am Dave Stokes I am MySQL Community Manager and have been using MySQL for over 20 years. @Stoker david.stokes @oracle.com Slides at slideshare.net/davidmstokes and github.com/davidmstokes/tutorials 2
  • 3. MySQL is a relational database & a NoSQL JSON Document Database • Community Edition – Free to use • Enterprise Edition – Starts at $5K/4 core CPU before discounts • You MUST buy a license if you ship MYSQL with your product GNU Public Licenses Version 2 3
  • 6. Relational Databases • Data is split up into tables • Tables can have relations • customer_id column in customer data and order data for common operations • Rich number of operations that can be performed on the data
  • 7. Structured query language (SQL) • Kinda of like English (does not always make sense) • VERBS • SELECT to ask questions • INSERT to add data • DELETE to remove data • UPDATE to, well, update data • SELECT name, phone FROM friends WHERE name = ‘Dave’; 7
  • 8. POP Quiz -- SQL Verbs How do you pick out data? How do you correct data? How do you add data? How do you remove data? 8 X X X X
  • 9. POP Quiz -- SQL Verbs How do you pick out data? How do you correct data? How do you add data? How do you remove data? 9 SELECT X X X
  • 10. POP Quiz -- SQL Verbs How do you pick out data? How do you correct data? How do you add data? How do you remove data? 10 SELECT UPDATE X X
  • 11. POP Quiz -- SQL Verbs How do you pick out data? How do you correct data? How do you add data? How do you remove data? 11 SELECT UPDATE INSERT X
  • 12. POP Quiz -- SQL Verbs How do you pick out data? How do you correct data? How do you add data? How do you remove data? 12 SELECT UPDATE INSERT DELETE
  • 13. How did you do? 13
  • 14. Data stored in rows within a table • Tables have rows of data • Tables made up of columns • Similar to a spreadsheet Multiple tables per schema • Database/schema often used interchangeably in MySQL • You can have multiple schemas per server 14 Column A Column B data data data data
  • 16. Not actually installing software If you have a copy of the MySQL server and a client program please feel free to follow along. But there are too many variable to get everyone up and running in the allotted time.
  • 17. https://dev.mysql.com/downloads • Linux • Apt Repo for Debian based systems • YUM repo for Redhat-ish systems • Binaries • Mac OS • Windows • Installer • Binaries • Source Code • Docker 17
  • 18. Make sure it is MySQL • Some Linux distributions switched to MariaDB, a fork of MySQL created when Oracle took over MySQL and will NOT give you MySQL when you ask for it. MariaDB is not a drop in replacement for MySQL and lacks many features that you may want that are in MySQL only. 18
  • 19. Using the MySQL apt repo • https://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/ • Go to the download page for the MySQL APT repository at https://dev.mysql.com/downloads/repo/apt/ • shell> sudo dpkg -i mysql-apt-config_w.x.y-z_all.deb • shell> sudo apt-get update • shell> sudo apt-get install mysql-server • shell> sudo service mysql start 19
  • 20. Using the MySQL RPM repo • Go to the download page for MySQL Yum repository at https://dev.mysql.com/downloads/repo/yum/ • shell> sudo rpm -Uvh mysql80-community-release-el6-n.noarch.rpm • shell> sudo yum install mysql-community-server • shell> sudo systemctl start mysqld.service 20
  • 21. Other installation notes • Refer to the MySQL documentation at https://dev.mysql.com for help with your installation • The MySQL demo databases are found at https://dev.mysql.com/doc/index-other.html • You may want the mysql cli client (mysql), mysql shell (mysqlsh), and MySQL Workbench => please drop by MySQL table in expo area for a demo!! 21
  • 22. 2. Communicating with the MySQL server Choices - choices
  • 23. 23 Most people think as the database residing on a server somewhere in a computer room (or the cloud) and the client as a laptop or desktop computer. This is called the client server model of computing. BTW databases run just fine on laptops too !
  • 24. 24 I recommend installing you favorite Linux on an older laptop and using the MySQL Repositories to learn MySQL
  • 25. Starting the server • The mysqld program (MySQL Daemon) runs in the background on your Linux system. It normally listens on port 3306 (and the new NoSQL service listens on port 33060) for programs wanting to communicate with it • The command line program to talk to the mysqld daemon is named mysql • $ mysql –u user -p PASSWORD: ******** 25
  • 26. The mysql client Example 26 mysql - cli program -u texas00 - user -p - ask for password
  • 27. The new MySQl Shell or mysqlsh • MySQL 8.0 has another shell named mysqlsh • $ mysqlsh • Features • Command completion • Improved help facility • Three modes – JavaScript, Python & SQL • Utility functions for admin work • Check for server upgrade, JSON bulk loader, Cluster Administration 27
  • 30. 3. First Data Set Simple sample data
  • 31. World data • Used for MySQL documentation, tutorials, training, etcetera • Out of date data but still useful for illustration purposes • Download from https://dev.mysql.com/doc/index-other.html • Extract the data with $gunzip world.sql.gz • • $mysql u root –p < world.sql This has already been done in demo accounts But documented for those using the notes later! 31
  • 32. Explanation • mysql –u root –p < world.sql • mysql is the name of the cli program • -u root tells server we want to use the account as the user root • -p is used if the account has a password and the password will be asked from you • < world.sql the < command on the Linux shell redirects input from the file named world.sql into the mysql cli program 32
  • 33. The use command • The MySQL server can support many databases (proper term is schemas) and need to be told which one you want to use. We just created a schema named world when we loaded data. • $ mysql –u <account> –p Password: ****** • mysql> USE world; Database changed; mysql> 33
  • 34. Uppercase/Lowercase • The MySQL server is case insensitive for commands if your operating system is also case insensitive. For illustration SQL commands will be in UPPERCASE and the stuff you need to type is in bold. • $ mysql –u root –p Password: ****** • mysql> USE world; Database changed • mysql> SHOW SCHEMAS; 34
  • 35. So what do we have??? mysql> SHOW TABLES; +-----------------+ | Tables_in_world | +-----------------+ | city | | country | | countrylanguage | +-----------------+ 3 rows in set (0.01 sec) mysql> 35
  • 36. So what do we have??? mysql> SHOW TABLES; +-----------------+ | Tables_in_world | +-----------------+ | city | | country | | countrylanguage | +-----------------+ 3 rows in set (0.01 sec) mysql> We have three tables – city, country, and countrylanguage – in our schema that can be queried (ask for information) for data. 36
  • 37. QUICK quiz In a relational database, the data is organized within _________ and the data is kept in _______ 37
  • 38. QUICK quiz In a relational database, the data is organized within SCHEMAS (or databases) and the data is kept in TABLES 38
  • 39. 4.Structured Query Language How to ask a database questions
  • 40. Entity Relationship Map of world schema 40
  • 41. the city and countrycode tables have been set up with a CountryCode column to relate to the code column in the countrytable’s 41
  • 42. SQL or structured query language • Designed in the 1970s • Minimize data duplication • Set theory and relational calculus • When disks and memory were EXPENSIVE • Still used today extensively • Divided into two parts • Data Definition Language or DDL • What the data looks like (Integer, Text, JSON, Geometry, …) • Data Manipulation Language • Looking at the data or DML 42
  • 43. The basic commands -> Think verbs (action words) • SELECT • Get data from a table • INSERT • Put data into the table • UPDATE • Change data in a table • DELETE • Remove data in a table 43 We covered these ‘verbs’ earlier and they are the core of most queries that you will ever write.
  • 44. Our First query mysql> SELECT * FROM city LIMIT 1; • SELECT – ask server for data • * - Wildcard for all columns in a row of data • FROM city - the name of the table we want to use • (case must match) • LIMIT 1 – We want a maximum of one row of data • ; - Tells the server we are done with this command and it can be run. 44
  • 45. Wildcards: * = all columns in a table % = Matches 1 or more characters %name matches first_name and last_name 45
  • 46. Our First query mysql> SELECT * FROM city LIMIT 1; +----+-------+-------------+----------+------------+ | ID | Name | CountryCode | District | Population | +----+-------+-------------+----------+------------+ | 1 | Kabul | AFG | Kabol | 1780000 | +----+-------+-------------+----------+------------+ 1 row in set (0.25 sec) mysql> 46
  • 47. Our First query mysql> SELECT * FROM city LIMIT 1; +----+-------+-------------+----------+------------+ | ID | Name | CountryCode | District | Population | +----+-------+-------------+----------+------------+ | 1 | Kabul | AFG | Kabol | 1780000 | +----+-------+-------------+----------+------------+ 1 row in set (0.25 sec) mysql> The first record has the fields ID, Name, CountryCode, District, and Population fields for the city of Kabul 47
  • 48. Our First query mysql> SELECT * FROM city LIMIT 1; +----+-------+-------------+----------+------------+ | ID | Name | CountryCode | District | Population | +----+-------+-------------+----------+------------+ | 1 | Kabul | AFG | Kabol | 1780000 | +----+-------+-------------+----------+------------+ 1 row in set (0.25 sec) mysql> Note that some columns are numbers only and some are alphanumeric 48
  • 49. Experiment What happens if you do not use LIMIT 1 ??? 49
  • 50. Experiment What happens if you do not use LIMIT 1 ??? You get to see 4079 rows! 50
  • 51. What if we want to get more specific? • We only want the city name • And those cities need to be in Texas • * We will cheat and assume that somehow we know that cities in Texas are designated by having the district column = Texas 51
  • 52. The query • mysql> SELECT name FROM city WHERE DISTRICT = 'Texas'; 52
  • 53. The query –Also acceptable • mysql> SELECT name FROM city WHERE DISTRICT = 'Texas'; 53 Readability is VERY important and you may prefer to break the query up over several lines.
  • 54. The query • mysql> SELECT name FROM city WHERE DISTRICT = 'Texas'; • SELECT name - Ask for the name column data • FROM city - The table with the data • WHERE - Specify constraints • DISTRICT = ‘Texas’ - The constraint • ; - Done with the query 54
  • 55. The output +----------------+ | name | +----------------+ | Houston | | Dallas | | San Antonio | | Austin | | El Paso | | Fort Worth | | Arlington | | Corpus Christi | | Plano | | Garland | | Lubbock | | Irving | | Laredo | | Amarillo | | Brownsville | | Pasadena | | Grand Prairie | | Mesquite | | Abilene | | Beaumont | | Waco | | Carrollton | | McAllen | | Wichita Falls | | Midland | | Odessa | +----------------+ 26 rows in set (0.00 sec) 55
  • 56. The output +----------------+ | name | +----------------+ | Houston | | Dallas | | San Antonio | | Austin | | El Paso | | Fort Worth | | Arlington | | Corpus Christi | | Plano | | Garland | | Lubbock | | Irving | | Laredo | | Amarillo | | Brownsville | | Pasadena | | Grand Prairie | | Mesquite | | Abilene | | Beaumont | | Waco | | Carrollton | | McAllen | | Wichita Falls | | Midland | | Odessa | +----------------+ 26 rows in set (0.00 sec) 26 Cities in the table with the District = ‘Texas’! Note they are not sorted alphabetically * * Usually there is no guarantee on the order of the data returned from the server 56
  • 57. WHERE -- The clause to narrow down your search The WHERE clause in a SQL query is used to narrow down the query to the specific record(s). WHERE age > 21 WHERE customer_id = 26378 AND amount_due > 0 WHERE seat_row BETWEEN 2 AND 3 57
  • 58. Sort by the name of the city SELECT name FROM city AS city_name WHERE DISTRICT = 'Texas' ORDER BY name; FROM city AS city_name tells the server we want to alias the name column as refer to is as city_name ORDER BY name tells the server we want the results SORTED by the column name 58
  • 59. The output +----------------+ | name | +----------------+ | Abilene | | Amarillo | | Arlington | | Austin | | Beaumont | | Brownsville | | Carrollton | | Corpus Christi | | Dallas | | El Paso | | Fort Worth | | Garland | | Grand Prairie | | Houston | | Irving | | Laredo | | Lubbock | | McAllen | | Mesquite | | Midland | | Odessa | | Pasadena | | Plano | | San Antonio | | Waco | | Wichita Falls | +----------------+ 59
  • 60. Experiment What happens if you use ORDER BY name DESC??? 60
  • 61. Experiment What happens if you use ORDER BY name DESC??? The results are sorted in DESCending order, W-A 61
  • 62. 5. JOINing tables How to get data from two tables (or more)
  • 63. Normalizing data Splitting up the various pieces of data into separate tables is called normalizing. So the details on a customer are kept in a customer table and their order information is stored in a order table. So by using the customer ID number from the customer table, yoy can look up their orders on the order table SELECT * FROM orders WHERE customer_id = 35882; 63
  • 64. Relational tables • Data is ‘normalized’ to group similar information together • Different tables hold different sets of information • The world schema has three tables • City information – city • Country information – country • Country languages - countrylanguage
  • 65. World Schema Entity Relationship Map 65 Someone has set up the tables so that they link through a column that is in all three of the schemas! Both the city and countrylangauge tables have columns named CountryCode that match up with the Code column in the country table.
  • 66. country Table code 66 Keys between tables countrylanguage table countrycode city table countrycodeWe can cross reference data in different tables with a column that have a common value or values
  • 67. country Table code = ‘USA’ (1 entry) 67 Keys between tables countrylanguage table countrycode = ‘USA’ (1 or more entry) city table countrycode = ‘USA’ (1 or more entry If we wanted to find all the records that mention ‘USA’ we would find one record in the country table and one or more entries in the city and countryinfo tables.
  • 68. JOINing two tables together mysql> SELECT City.name, Country.name AS Country FROM City JOIN Country on (City.countrycode = Country.code) WHERE City.name = 'Irving'; +--------+---------------+ | name | Country | +--------+---------------+ | Irving | United States | +--------+---------------+ 1 row in set (0.00 sec) mysql> 68
  • 69. JOINing two tables together mysql> SELECT City.name, - ask for the name from city Country.name AS Country - ask for the name from country FROM City ‘alias’ name as Country JOIN Country on - match the two tables (City.countrycode = Country.code) WHERE City.name = 'Irving'; - for the record that matches +--------+---------------+ the city of Irving | name | Country | +--------+---------------+ | Irving | United States | +--------+---------------+ 1 row in set (0.00 sec) mysql> 69
  • 70. Joins can be complex Joins let you drill down precisely to the desired information 70
  • 71. Complex Example – you can work up to this!! SELECT CONCAT(customer.last_name, ', ', customer.first_name) AS customer, address.phone, film.title FROM rental INNER JOIN customer ON rental.customer_id = customer.customer_id INNER JOIN address ON customer.address_id = address.address_id INNER JOIN inventory ON rental.inventory_id = inventory.inventory_id INNER JOIN film ON inventory.film_id = film.film_id WHERE rental.return_date IS NULL AND rental_date + INTERVAL film.rental_duration DAY < 71
  • 73. Break number one Fifteen minutes and no more please!! 73
  • 74. 6. Data Definition Language Creating your own table 74
  • 75. CREATE TABLE mysql> CREATE TABLE foo ( -> id INT, -> name CHAR(20) -> ); Query OK, 0 rows affected (0.07 sec) mysql>
  • 76. CREATE TABLE mysql> CREATE TABLE foo ( -> id INT, -> name CHAR(20) -> ); Query OK, 0 rows affected (0.07 sec) mysql> This creates a table named foo that has two columns – id for integer data, and name for character data.
  • 77. Data types MySQL has several types of data to meet you needs • Numeric • Character (usually a-zA-Z & special characters like @#&!) • Date/Time • String • JSON documents • Spatial (Graphic Information, think GPS) • We will deal only with INT and CHAR() types (for now) 77
  • 78. The next few slides are for illustration Do not worry of these details are too much for now I just want to show that there are many different types of data that can be stored in a database 78
  • 79. Numeric 79 Type Storage (BYTES) Minimum Singed Value Minimum Unsigned Value Maximum Signed Value Maximum Unsigned Value TINYINT 1 -128 0 127 366 SMALLINT 2 -32768 0 32767 65535 MEDIUMINT 3 -8388608 0 8388607 16777215 INT 4 -2147483648 0 2147483647 4294967295 BIGINT 8 -263 0 263-1 264-1
  • 80. Textual • CHAR(n) – Holds characters A-Za-z0-9!@#$%^&*() plus more • VARCHAR(n) – Variable length version, extra space need to note length • Where n is the number of character to be held. 80
  • 81. CREATE TABLE - revisited mysql> CREATE TABLE foo ( -> id INT, -> name CHAR(10) -> ); Query OK, 0 rows affected (0.07 sec) mysql> This is an example of the Data Definition Language (DDL) to create a table. The table has two columns – id & name – to store data.
  • 82. What happens if a name is longer than 10 characters? 82
  • 83. What happens if a name is longer than 10 characters? 83 mysql> INSERT INTO foo (id,name) VALUES (1,'ThisNameIsTooLong'); ERROR 1406 (22001): Data too long for column 'name' at row 1
  • 84. INSERT INTO foo (id,name) VALUES (1,‘Dave'); • INSERT – the action we want to perform • INTO foo – where the data is going – a TABLE named ‘foo’ • (id,name) – specify the columns to be filled • VALUES - ‘What comes next is the data we want to store in ‘foo’ • (1,’Dave’) - the data • ; - designates ‘end of query’ 84
  • 85. Let’s add some data mysql> INSERT INTO foo (id,name) VALUES (1,'Dave'); Query OK, 1 row affected (0.01 sec) 85
  • 86. Let’s add some data mysql> INSERT INTO foo (id,name) VALUES (1,'Dave'); Query OK, 1 row affected (0.01 sec) mysql> SELECT id, name FROM foo; +------+------+ | id | name | +------+------+ | 1 | Dave | +------+------+ 1 row in set (0.00 sec) mysql> 86
  • 87. Let’s add some data mysql> INSERT INTO foo (id,name) VALUES (1,'Dave'); Query OK, 1 row affected (0.01 sec) mysql> SELECT id, name FROM foo; +------+------+ | id | name | +------+------+ | 1 | Dave | +------+------+ 1 row in set (0.00 sec) mysql> 87
  • 88. EXERCISE -> Follow along • Start your MySQL Client • Create a schema named ‘texas’ msqyl>CREATE SCHEMA texas; • ‘Point’ to that schema mysql>USE texas; • Create table from previous slide • Input some data using your name or nickname (under 10 characters and your lucky number 88 mysql> CREATE TABLE foo ( -> id INT, -> name CHAR(20) -> );
  • 89. Inputting data • INSERT INTO foo (id,name) VALUES (1,'Dave'); • INSERT INTO – The action we want to do foo - the table we want to store data (id,name) - the data fields VALUES - tells server data is next (1,'Dave'); - the actual data 89
  • 90. Looking at the data we just stored SELECT id, name FROM foo; SELECT id FROM foo; SELECT name FROM foo; SELECT name, id FROM foo; SELECT * FROM foo; -- * is a wildcard 90
  • 91. What we have learned, command wise • INSERT • SELECT • CREATE schema • CREATE table • USE schema • SHOW SCHEMAS; 91
  • 92. Modify the table by adding another column mysql> ALTER TABLE foo ADD COLUMN zip char(5); Query OK, 0 rows affected (0.07 sec) Records: 0 Duplicates: 0 Warnings: 0 92
  • 93. Why a char over an INTEGER? Unless you specify most numeric values will truncate leading zeros so it is often better to have data such as zipcodes that WILL HAVE leading zeros as characters to ensure you keep those leading zeros! Stuff Alex Trebeck Will Not EVER ask ME 93
  • 94. ALTER TABLE foo ADD COLUMN zip char(5); ALTER TABLE -- Task to be done, adding column foo -- The name of table to ALTER ADD COLUMN -- What action to be done zip -- Name of the new column char(5) -- What type of data needed ; -- ; is the end of query 94
  • 95. Create a second table And add a PRIMARY key
  • 96. PEts! What if you wanted to track pets in your neighborhood? What information would you want to keep? Name Type Owner ? 96
  • 97. Normalize data Name -- How many characters do we need to save names? How about for the other fields? 97
  • 98. Create table CREATE TABLE pets ( ); 98 Here is where we define that columns we need to store the data we want to keep!
  • 99. Switch to demo screen For those of you downloading the slides, this part of the tutorial is a live demo of creating the table for the pets data. 99
  • 100. Indexes also know as a key • Without an index the entire database/file needs to be read to find the data, pronounced ‘s l o w’! • An index on a column lets you go directly to the matching column(s) • By default, MySQL wants an index and will create one for you if you do not have one • And it usually picks one that you do not want • And its pick may not be the best for performance • So pick you own column or columns to index 100
  • 101. 101 CREATE TABLE pets2 ( id INTEGER AUTO_INCREMENT PRIMARY KEY, name CHAR(25), type CHAR(20), breed CHAR(25), owner CHAR(30), contact CHAR(50)); Query OK, 0 rows affected (0.0618 sec)
  • 102. 102 CREATE TABLE pets2 ( id INTEGER AUTO_INCREMENT PRIMARY KEY, name CHAR(25), type CHAR(20), breed CHAR(25), owner CHAR(30), contact CHAR(50)); Query OK, 0 rows affected (0.0618 sec)
  • 103. 103 What is PRIMARy KEY? The primary key is the main index on a table Hopefully this is a column that you will want/need to search on later
  • 104. 104 What is AUTO_INCReMENT? Every time you add a record to a table with an autoincrement column, the number is AUTOMATICALLY incremented • When inserting data either do not name that column • Or pass a NULL for the value
  • 105. 105 mysql>INSERT INTO pets2 (id,name) VALUES (NULL,'Bob'), (NULL,'Kitty'); Query OK, 2 rows affected (0.0139 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> SELECT id,name FROM pets2; +----+-------+ | id | name | +----+-------+ | 1 | Bob | | 2 | Kitty | +----+-------+ 2 rows in set (0.0004 sec) The server automatically assigned the values for the id column.
  • 106. 106
  • 107. 107 CREATE TABLE timekeeper (x INT AUTO_INCREMENT PRIMARY KEY, ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, dt DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ); Query OK, 0 rows affected (0.0421 sec)
  • 108. 108 INSERT INTO timekeeper (x) VALUES (NULL); Query OK, 1 row affected (0.0068 sec) SELECT * FROM timekeeper; +---+---------------------+---------------------+ | x | ts | dt | +---+---------------------+---------------------+ | 1 | 2019-05-18 09:35:16 | 2019-05-18 09:35:16 | +---+---------------------+---------------------+ 1 row in set (0.0005 sec)
  • 109. 109 ALTER TABLE timekeeper ADD COLUMN y INT DEFAULT 0; UPDATE timekeeper SET y=1 WHERE x=1; Query OK, 1 row affected (0.0089 sec) Rows matched: 1 Changed: 1 Warnings: 0 SELECT * FROM timekeeper; +---+---------------------+---------------------+---+ | x | ts | dt | y | +---+---------------------+---------------------+---+ | 1 | 2019-05-18 09:38:22 | 2019-05-18 09:38:22 | 1 | +---+---------------------+---------------------+---+ 1 row in set (0.0006 sec) Note the time changed from 9:35 to 9:38
  • 110. 110 Differences between datestamp and time stamp DATETIME values is '1000-01-01 00:00:00.000000' to '9999-12-31 23:59:59.999999', TIMESTAMP values is '1970-01-01 00:00:01.000000' to '2038-01-19 03:14:07.999999'
  • 112. Software Download MySQL Server, MySQL Workbench, and test data Where to learn more Books Go to Half-Price Books and find a book on MySQL Or go online -> google ‘mysql intro’ And look at www.mysql.com 112
  • 113. There is a big demand for DBAs and Devs that know Databases A complex idea can be conveyed with just a single still image, namely making it possible to absorb large amounts of data quickly. 113
  • 114. “You learn more database concepts by ‘breaking things’ and learning how to fix them then by just reading the manual” 114
  • 115. Some other things that novices will run into that need some extra explanation Data Concepts
  • 116. Think: Bank taking funds from Customer A to pay Customer B TRANSACTION 1. Does Customer A have enough funds to cover? 2. Place holds on the accounts for Customer A & Customer B to keep other transactions from interfering with this transaction 3. Withdraw MONEY from Customer A 4. Deposit MONEY into Customer B’s account 5. Remove holds on both account 116 Transactions
  • 117. Locking records • Records are LOCKed to keep others from changing values in row • Others will have to wait for locks to be released (called BLOCKING) • You can lock records in many ways • SHARED • EXCLUSIVE 117
  • 118. Thanks! Any questions? You can find me at @stoker david.stokes @oracle.com Slideshare.net/davidmstokes 118