MySQL is a relational database management system. The document provides an introduction to MySQL, including:
- MySQL is available in both community and enterprise editions. The community edition is free to use while the enterprise edition starts at $5K/4 core CPU before discounts.
- Data in MySQL is organized into tables within schemas (or databases). Tables contain rows of data organized into columns.
- Structured Query Language (SQL) is used to interact with MySQL databases. Common SQL commands include SELECT to retrieve data, INSERT to add data, UPDATE to modify data, and DELETE to remove data.
- JOIN clauses allow retrieving data from multiple tables by linking them together on common columns. This helps normalize data
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)Dave Stokes
MySQL 8 has many new features and this presentation covers the new data dictionary, improved JSON functions, roles, histograms, and much more. Updated after SunshinePHP 2018 after feedback
Develop PHP Applications with MySQL X DevAPIDave Stokes
The X DevAPI provides a way to use MySQL as a NoSQL JSON Document Store and this presentation covers how to use it with the X DevAPI PHP PECL extension. And it also works with traditional relational tables. Presented at Oracle CodeOne 24 October 2018
MySQL can now be used as a NoSQL JSON Document store so you get the best of NoSQL and SQL world. This talk covers the features of the X Devapi, the MySQL Document Store, and how to use relational tables with the new SQL features
A Step by Step Introduction to the MySQL Document StoreDave Stokes
Looking for a fast, flexible NoSQL document store? And one that runs with the power and reliability of MySQL. This is an intro on how to use the MySQL Document Store
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)Dave Stokes
MySQL 8 has many new features and this presentation covers the new data dictionary, improved JSON functions, roles, histograms, and much more. Updated after SunshinePHP 2018 after feedback
Develop PHP Applications with MySQL X DevAPIDave Stokes
The X DevAPI provides a way to use MySQL as a NoSQL JSON Document Store and this presentation covers how to use it with the X DevAPI PHP PECL extension. And it also works with traditional relational tables. Presented at Oracle CodeOne 24 October 2018
MySQL can now be used as a NoSQL JSON Document store so you get the best of NoSQL and SQL world. This talk covers the features of the X Devapi, the MySQL Document Store, and how to use relational tables with the new SQL features
A Step by Step Introduction to the MySQL Document StoreDave Stokes
Looking for a fast, flexible NoSQL document store? And one that runs with the power and reliability of MySQL. This is an intro on how to use the MySQL Document Store
Confoo 2021 - MySQL Indexes & HistogramsDave Stokes
Confoo 2021 presentation on MySQL Indexes, Histograms, and other ways to speed up your queries. This slide deck has slides that may not have been included in the presentation that were omitted due to time constraints
Confoo.ca conference talk February 24th 2021 on MySQL new features found in version 8.0 including server and supporting utility updates for those who may have missed some really neat new features
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScriptDave Stokes
The MySQL Shell has a JavaScript mode where you can use JS libraries to access you data and you can also write (and save) your own custom reports (or programs) for future use.
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...Dave Stokes
Speeding up queries on a MySQL server with indexes and histograms is not a mysterious art but simple engineering. This presentation is an indepth introduction that was presented on March 30th to the Quest Insynch and Open Source 101 conferences
Adding Value to HBase with IBM InfoSphere BigInsights and BigSQLPiotr Pruski
This is the extended deck I used for my presentation at the Information On Demand 2013 conference for Session Number 1687 - Adding Value to HBase with IBM InfoSphere BigInsights and BigSQL.
This presentation covers accessing HBase using Big SQL. It starts by going over general HBase concepts, than delves into how Big SQL adds an SQL layer on top of HBase (via HBase storage handler), secondary index support, queries, etc.
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...Dave Stokes
Slow query? Add an index or two! But things are suddenly even slower! Indexes are great tools to speed data lookup but have overhead issues. Histograms don’t have that overhead but may not be suited. And how you lock rows also effects performance. So what do you do to speed up queries smartly?
Microsoft SQL Server Data Warehouses for SQL Server DBAsMark Kromer
This is my presentation for SQL Saturday Philly 2012. The topic is managing SQL Server data warehouses with a look at the SQL Server data warehouse landscape and the challenges that a DBA must prepare for in large DW workloads and BI solutions.
Python Utilities for Managing MySQL DatabasesMats Kindahl
Managing a MySQL database server can become a full time job. What we need are tools that bundle a set of related tasks into a common utility. While there are several such utility libraries to choose, it is often the case that you need to customize them to your needs. The MySQL Utilities library is the answer to that need. It is open source so you can modify and expand it as you see fit.
This is the presentation from OSCON 2011 in Portland.
Confoo 2021 - MySQL Indexes & HistogramsDave Stokes
Confoo 2021 presentation on MySQL Indexes, Histograms, and other ways to speed up your queries. This slide deck has slides that may not have been included in the presentation that were omitted due to time constraints
Confoo.ca conference talk February 24th 2021 on MySQL new features found in version 8.0 including server and supporting utility updates for those who may have missed some really neat new features
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScriptDave Stokes
The MySQL Shell has a JavaScript mode where you can use JS libraries to access you data and you can also write (and save) your own custom reports (or programs) for future use.
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...Dave Stokes
Speeding up queries on a MySQL server with indexes and histograms is not a mysterious art but simple engineering. This presentation is an indepth introduction that was presented on March 30th to the Quest Insynch and Open Source 101 conferences
Adding Value to HBase with IBM InfoSphere BigInsights and BigSQLPiotr Pruski
This is the extended deck I used for my presentation at the Information On Demand 2013 conference for Session Number 1687 - Adding Value to HBase with IBM InfoSphere BigInsights and BigSQL.
This presentation covers accessing HBase using Big SQL. It starts by going over general HBase concepts, than delves into how Big SQL adds an SQL layer on top of HBase (via HBase storage handler), secondary index support, queries, etc.
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...Dave Stokes
Slow query? Add an index or two! But things are suddenly even slower! Indexes are great tools to speed data lookup but have overhead issues. Histograms don’t have that overhead but may not be suited. And how you lock rows also effects performance. So what do you do to speed up queries smartly?
Microsoft SQL Server Data Warehouses for SQL Server DBAsMark Kromer
This is my presentation for SQL Saturday Philly 2012. The topic is managing SQL Server data warehouses with a look at the SQL Server data warehouse landscape and the challenges that a DBA must prepare for in large DW workloads and BI solutions.
Python Utilities for Managing MySQL DatabasesMats Kindahl
Managing a MySQL database server can become a full time job. What we need are tools that bundle a set of related tasks into a common utility. While there are several such utility libraries to choose, it is often the case that you need to customize them to your needs. The MySQL Utilities library is the answer to that need. It is open source so you can modify and expand it as you see fit.
This is the presentation from OSCON 2011 in Portland.
MySQL Without the SQL -- Oh My! Longhorn PHP ConferenceDave Stokes
You can now use MySQL without needing to know Structured Query Language (SQL) with the MySQL Document Store. Access JSON documents and/or relational tables using the new X DevAPI
Access Data from XPages with the Relational ControlsTeamstudio
Did you know that Domino and XPages allows for the easy access of relational data? These exciting capabilities in the Extension Library can greatly enhance the capability of your applications and allow access to information beyond Domino. Howard and Paul will discuss what you need to get started, what controls allow access to relational data, and the new @Functions available to incorporate relational data in your Server Side JavaScript programming.
Fewer developers each year are getting training in Structured Query Language (SQL) but their code is more dependent on Relation Data. The MySQL Document Store allows programmers to use the full power of MySQL without needing SQL! Built on the X DevAPI, the MySQL Document Store is a power tool for working with JSON Document Store or relational tables. Best of both NoSQL and SQL worlds!
Geek Sync I Need for Speed: In-Memory Databases in Oracle and SQL ServerIDERA Software
You can watch the replay for this Geek Sync webcast in the IDERA Resource Center: http://ow.ly/S6MG50A5ok5
Microsoft introduced IN-MEMORY OLTP, widely referred to as “Hekaton” in SQL Server 2014. Hekaton allows for the creation of fully transactionally consistent memory-resident tables designed for high concurrency and no blocking. With SQL 2016, many of the original restrictions and limitations of this feature have been reduced. IDERA’s Vicky Harp will give an overview of this feature, including how to compile T-SQL code into machine code for an even greater performance boost.
There’s also been a lot of buzz about Oracle 12c’s new IN-MEMORY COLUMN STORE. Oracle ACE Bert Scalzo will cover this new feature, how it works, it’s benefits, scripts to measure/monitor it and more. He will also touch on performance observations from benchmarking this new feature against more traditional SGA memory allocations plus Oracle 11g R2’s Database Smart Flash Cache. All findings, scripts and conclusions from this exercise will be shared. In addition, two very popular database benchmarking tools will be highlighted.
Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...Databricks
Spark SQL is a highly scalable and efficient relational processing engine with ease-to-use APIs and mid-query fault tolerance. It is a core module of Apache Spark. Spark SQL can process, integrate and analyze the data from diverse data sources (e.g., Hive, Cassandra, Kafka and Oracle) and file formats (e.g., Parquet, ORC, CSV, and JSON). This talk will dive into the technical details of SparkSQL spanning the entire lifecycle of a query execution. The audience will get a deeper understanding of Spark SQL and understand how to tune Spark SQL performance.
Similar to MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019 (20)
MySQL is an ubiquitous open source database but do you know how make it secure? This talk is from the 2022 Texas Cyber Summit on how to do just that. Make sure you data and database are secure.
MySQL Indexes and Histograms - RMOUG Training Days 2022Dave Stokes
Nobody complains when the database is too fast. But they do gripe when it slows down. The two most popular ways to increase query speed are indexes and histograms. But there a dozens of options for indexes and a lot of lots of bad information on how to use them. Histograms are great but not for all types of data. This session covers the hows and whys of both approaches
The Proper Care and Feeding of MySQL DatabasesDave Stokes
Many Linux System Administrators are 'also' accidental database administrators. This is a guide for them to keep their MySQL database instances happy, health, and glowing
MySQL Without The SQL -- Oh My! PHP[Tek] June 2018Dave Stokes
The MySQL Document Store allows developers to use MySQL as a JSON Document Store -- no normalizing of data, setting up relational tables, and you do not have to use SQL to query data. And you get the both the SQL and NoSQL worlds on one server
Presentation Skills for Open Source FolksDave Stokes
Do you want to present at a Linuxfest or other open source conference but do not know where or how to start. Follow these recommendations and you will be on your way to being a speaking all star. Discover how write your presentation. what tools you need, and other items of note
ConFoo MySQL Replication Evolution : From Simple to Group ReplicationDave Stokes
MySQL Replication has been around for many years but how wee do you under stand it? Do you know about read/write splitting, RBR vs SBR style replication, and InnoDB cluster?
This presentation is an INTRODUCTION to intermediate MySQL query optimization for the Audience of PHP World 2017. It covers some of the more intricate features in a cursory overview.
SwanseaCon 2017 presentation on Making MySQL Agile-ish. Relational Databases are not usually considered part of the Agile Programming movement but there are many new features in MySQL to make it easier to include it. This presentation covers how MySQL is moving to help support agile development while maintaining the traditional 'non agile' stability expected from a database.
The very basics of programming in PHP to store/retrieve data on a relational database management system (RDMS). For those looking for intermediate to advanced material, please see 'What Your Database Query is Really Doing'.
MySQL Replication Evolution -- Confoo Montreal 2017Dave Stokes
MySQL Replication has evolved since the early days with simple async master/slave replication with better security, high availability, and now InnoDB Cluster
Five Database Mistakes and how to fix them -- Confoo VancouverDave Stokes
Very few developers are learning Structured Query Language (about 2%) but then wonder why their database queries stink. This presentation covers five common database problems and how to fix them
All Things Open 2016 -- Database Programming for NewbiesDave Stokes
This presentation covers much a new developer needs to know about working WITH a database instead of against it. Plus there is much on what goes on behind the scenes when you submit a query and hints on how to avoid the big problems that can ruin your data
MySQL Replication Update -- Zendcon 2016Dave Stokes
How does MySQL work at a conceptual level and at a how-to-do-it level is covered in this presentation plus information on other replication options like Group Replication and Multi Master
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesSanjeev Rampal
Talk presented at Kubernetes Community Day, New York, May 2024.
Technical summary of Multi-Cluster Kubernetes Networking architectures with focus on 4 key topics.
1) Key patterns for Multi-cluster architectures
2) Architectural comparison of several OSS/ CNCF projects to address these patterns
3) Evolution trends for the APIs of these projects
4) Some design recommendations & guidelines for adopting/ deploying these solutions.
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC
Ellisha Heppner, Grant Management Lead, presented an update on APNIC Foundation to the PNG DNS Forum held from 6 to 10 May, 2024 in Port Moresby, Papua New Guinea.
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBrad Spiegel Macon GA
Brad Spiegel Macon GA’s journey exemplifies the profound impact that one individual can have on their community. Through his unwavering dedication to digital inclusion, he’s not only bridging the gap in Macon but also setting an example for others to follow.
1.Wireless Communication System_Wireless communication is a broad term that i...JeyaPerumal1
Wireless communication involves the transmission of information over a distance without the help of wires, cables or any other forms of electrical conductors.
Wireless communication is a broad term that incorporates all procedures and forms of connecting and communicating between two or more devices using a wireless signal through wireless communication technologies and devices.
Features of Wireless Communication
The evolution of wireless technology has brought many advancements with its effective features.
The transmitted distance can be anywhere between a few meters (for example, a television's remote control) and thousands of kilometers (for example, radio communication).
Wireless communication can be used for cellular telephony, wireless access to the internet, wireless home networking, and so on.
# Internet Security: Safeguarding Your Digital World
In the contemporary digital age, the internet is a cornerstone of our daily lives. It connects us to vast amounts of information, provides platforms for communication, enables commerce, and offers endless entertainment. However, with these conveniences come significant security challenges. Internet security is essential to protect our digital identities, sensitive data, and overall online experience. This comprehensive guide explores the multifaceted world of internet security, providing insights into its importance, common threats, and effective strategies to safeguard your digital world.
## Understanding Internet Security
Internet security encompasses the measures and protocols used to protect information, devices, and networks from unauthorized access, attacks, and damage. It involves a wide range of practices designed to safeguard data confidentiality, integrity, and availability. Effective internet security is crucial for individuals, businesses, and governments alike, as cyber threats continue to evolve in complexity and scale.
### Key Components of Internet Security
1. **Confidentiality**: Ensuring that information is accessible only to those authorized to access it.
2. **Integrity**: Protecting information from being altered or tampered with by unauthorized parties.
3. **Availability**: Ensuring that authorized users have reliable access to information and resources when needed.
## Common Internet Security Threats
Cyber threats are numerous and constantly evolving. Understanding these threats is the first step in protecting against them. Some of the most common internet security threats include:
### Malware
Malware, or malicious software, is designed to harm, exploit, or otherwise compromise a device, network, or service. Common types of malware include:
- **Viruses**: Programs that attach themselves to legitimate software and replicate, spreading to other programs and files.
- **Worms**: Standalone malware that replicates itself to spread to other computers.
- **Trojan Horses**: Malicious software disguised as legitimate software.
- **Ransomware**: Malware that encrypts a user's files and demands a ransom for the decryption key.
- **Spyware**: Software that secretly monitors and collects user information.
### Phishing
Phishing is a social engineering attack that aims to steal sensitive information such as usernames, passwords, and credit card details. Attackers often masquerade as trusted entities in email or other communication channels, tricking victims into providing their information.
### Man-in-the-Middle (MitM) Attacks
MitM attacks occur when an attacker intercepts and potentially alters communication between two parties without their knowledge. This can lead to the unauthorized acquisition of sensitive information.
### Denial-of-Service (DoS) and Distributed Denial-of-Service (DDoS) Attacks
This 7-second Brain Wave Ritual Attracts Money To You.!nirahealhty
Discover the power of a simple 7-second brain wave ritual that can attract wealth and abundance into your life. By tapping into specific brain frequencies, this technique helps you manifest financial success effortlessly. Ready to transform your financial future? Try this powerful ritual and start attracting money today!
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
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
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
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
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
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
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
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
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
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.
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
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.
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