Post on 23-Jun-2020
Overview of MySQLIntroduction to SQL
DBMS - Introduction to MySQL
Robert Lowe
Division of Mathematics and Computer ScienceMaryville College
February 9, 2016
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Outline
1 Overview of MySQL
2 Introduction to SQL
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Outline
1 Overview of MySQL
2 Introduction to SQL
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
MySQL Basics
Created by Monty Widenius and David Axmark in 1995One of the "Crown Jewels" of Open Source SoftwareEnterprise class database server with many advancedfeatures
Stored ProceduresTriggersLoad BalancingReplication
Client-Server system, where the MySQL daemon servesboth network and local socket requests.Programmable using SQLMulti-User with robust permissions
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
MySQL Basics
Created by Monty Widenius and David Axmark in 1995
One of the "Crown Jewels" of Open Source SoftwareEnterprise class database server with many advancedfeatures
Stored ProceduresTriggersLoad BalancingReplication
Client-Server system, where the MySQL daemon servesboth network and local socket requests.Programmable using SQLMulti-User with robust permissions
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
MySQL Basics
Created by Monty Widenius and David Axmark in 1995One of the "Crown Jewels" of Open Source Software
Enterprise class database server with many advancedfeatures
Stored ProceduresTriggersLoad BalancingReplication
Client-Server system, where the MySQL daemon servesboth network and local socket requests.Programmable using SQLMulti-User with robust permissions
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
MySQL Basics
Created by Monty Widenius and David Axmark in 1995One of the "Crown Jewels" of Open Source SoftwareEnterprise class database server with many advancedfeatures
Stored ProceduresTriggersLoad BalancingReplication
Client-Server system, where the MySQL daemon servesboth network and local socket requests.Programmable using SQLMulti-User with robust permissions
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
MySQL Basics
Created by Monty Widenius and David Axmark in 1995One of the "Crown Jewels" of Open Source SoftwareEnterprise class database server with many advancedfeatures
Stored ProceduresTriggersLoad BalancingReplication
Client-Server system, where the MySQL daemon servesboth network and local socket requests.
Programmable using SQLMulti-User with robust permissions
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
MySQL Basics
Created by Monty Widenius and David Axmark in 1995One of the "Crown Jewels" of Open Source SoftwareEnterprise class database server with many advancedfeatures
Stored ProceduresTriggersLoad BalancingReplication
Client-Server system, where the MySQL daemon servesboth network and local socket requests.Programmable using SQL
Multi-User with robust permissions
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
MySQL Basics
Created by Monty Widenius and David Axmark in 1995One of the "Crown Jewels" of Open Source SoftwareEnterprise class database server with many advancedfeatures
Stored ProceduresTriggersLoad BalancingReplication
Client-Server system, where the MySQL daemon servesboth network and local socket requests.Programmable using SQLMulti-User with robust permissions
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Schemas and Databases
A schema is a collection of entities and relationships.
MySQL calls a schema a database.A database is the basic boundary within MySQLEntities are stored as rows in tablesAttributes are stored as columnsColumns are strictly typed
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Schemas and Databases
A schema is a collection of entities and relationships.MySQL calls a schema a database.
A database is the basic boundary within MySQLEntities are stored as rows in tablesAttributes are stored as columnsColumns are strictly typed
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Schemas and Databases
A schema is a collection of entities and relationships.MySQL calls a schema a database.A database is the basic boundary within MySQL
Entities are stored as rows in tablesAttributes are stored as columnsColumns are strictly typed
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Schemas and Databases
A schema is a collection of entities and relationships.MySQL calls a schema a database.A database is the basic boundary within MySQLEntities are stored as rows in tables
Attributes are stored as columnsColumns are strictly typed
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Schemas and Databases
A schema is a collection of entities and relationships.MySQL calls a schema a database.A database is the basic boundary within MySQLEntities are stored as rows in tablesAttributes are stored as columns
Columns are strictly typed
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Schemas and Databases
A schema is a collection of entities and relationships.MySQL calls a schema a database.A database is the basic boundary within MySQLEntities are stored as rows in tablesAttributes are stored as columnsColumns are strictly typed
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Overview of Data Types
MySQL stores data in strict types.
MySQL has a complex collection of data types.Numeric TypesString TypesDate and Time Types
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Overview of Data Types
MySQL stores data in strict types.MySQL has a complex collection of data types.
Numeric TypesString TypesDate and Time Types
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Overview of Data Types
MySQL stores data in strict types.MySQL has a complex collection of data types.Numeric Types
String TypesDate and Time Types
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Overview of Data Types
MySQL stores data in strict types.MySQL has a complex collection of data types.Numeric TypesString Types
Date and Time Types
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Overview of Data Types
MySQL stores data in strict types.MySQL has a complex collection of data types.Numeric TypesString TypesDate and Time Types
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Integer Types
Type Bytes Minimum MaximumTINYINT(M) 1 -128 127
0 255SMALLINT(M) 2 -32768 32767
0 65535INT(M) 4 -2147483648 2147483647
0 4294967295BIGINT(M) 8 -9223372036854775808 9223372036854775807
0 18446744073709551615Note that the M is optional and specifies the display width of the integers.
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Real Number Types
Fixed Point Types (Exact Math)DECIMAL(M,D) - Arbitrary precision decimal where M isprecision and d is decimal places.NUMERIC - Synonymous with DECIMALFloating Point TypesFLOAT - Floating point numberDOUBLE PRECISION - Double Precision Floating PointNumber
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Bits and Bools
BIT(M) - Specify a bitfield of M bits.BOOL and BOOLEAN - synonyms for TINYINT(1). 0 -false, nonzero - true
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
String Types
CHAR(M) - Fixed-width character field of M charactersVARCHAR(M) - Variable-width, null-terminated string ofmaximum length MBINARY(M) - Fixed-width binary data of M bytesVARBINARY(M) - Variable-width binary data of max MbytesBLOB - Binary Large Object Arbitrary size binary data.TEXT - Arbitrary sized character data.ENUM - Can store one of several predefined values.SET - You should not use this. Stores lists of values in onecolumn!!!
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Date and Time Types
DATE - Stores the dateDATETIME - Stores date and timeTIME - Stores timeTIMESTAMP - UNIX TimestampYEAR - Stores the Year
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Launching the Client
Basic launch looks like this:mysql -uuser -p
You can also select a default database.mysql -uuser -p dbname
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Launching the Client
Basic launch looks like this:mysql -uuser -p
You can also select a default database.mysql -uuser -p dbname
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Launching the Client
Basic launch looks like this:mysql -uuser -p
You can also select a default database.mysql -uuser -p dbname
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Basic Commands
Display available databases with SHOW DATABASESDisplay tables in the current database with SHOWTABLESView table structure with DESC tableNameView the currently selected database withSELECT DATABASE();
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Basic Commands
Display available databases with SHOW DATABASES
Display tables in the current database with SHOWTABLESView table structure with DESC tableNameView the currently selected database withSELECT DATABASE();
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Basic Commands
Display available databases with SHOW DATABASESDisplay tables in the current database with SHOWTABLES
View table structure with DESC tableNameView the currently selected database withSELECT DATABASE();
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Basic Commands
Display available databases with SHOW DATABASESDisplay tables in the current database with SHOWTABLESView table structure with DESC tableName
View the currently selected database withSELECT DATABASE();
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Basic Commands
Display available databases with SHOW DATABASESDisplay tables in the current database with SHOWTABLESView table structure with DESC tableNameView the currently selected database withSELECT DATABASE();
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Designing for MySQL
1 Build an ER Model2 Build a Crow’s Foot Diagram of the Model3 Select Types for All Attributes4 Write Schema Generation Script in SQL
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Outline
1 Overview of MySQL
2 Introduction to SQL
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
SQL Overview
Design in the 1970’s by Donald Chamberlin and RaymondF. BoyceSpecial Purpose Programming Language - RDBMSDeclarative Procedural Language
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
SQL Overview
Design in the 1970’s by Donald Chamberlin and RaymondF. Boyce
Special Purpose Programming Language - RDBMSDeclarative Procedural Language
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
SQL Overview
Design in the 1970’s by Donald Chamberlin and RaymondF. BoyceSpecial Purpose Programming Language - RDBMS
Declarative Procedural Language
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
SQL Overview
Design in the 1970’s by Donald Chamberlin and RaymondF. BoyceSpecial Purpose Programming Language - RDBMSDeclarative Procedural Language
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Structure of a Statement
A statement is a series of clauses which are terminated bya ";"Statements typically contain a command clause and aconditional clause.Commands are applied to rows which match theconditional clause.A null conditional clause matches all rows.
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Structure of a Statement
A statement is a series of clauses which are terminated bya ";"
Statements typically contain a command clause and aconditional clause.Commands are applied to rows which match theconditional clause.A null conditional clause matches all rows.
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Structure of a Statement
A statement is a series of clauses which are terminated bya ";"Statements typically contain a command clause and aconditional clause.
Commands are applied to rows which match theconditional clause.A null conditional clause matches all rows.
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Structure of a Statement
A statement is a series of clauses which are terminated bya ";"Statements typically contain a command clause and aconditional clause.Commands are applied to rows which match theconditional clause.
A null conditional clause matches all rows.
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Structure of a Statement
A statement is a series of clauses which are terminated bya ";"Statements typically contain a command clause and aconditional clause.Commands are applied to rows which match theconditional clause.A null conditional clause matches all rows.
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
CRUD
CreateReadUpdateDelete
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Creation
CREATE DATABASE - Creates a new SchemaCREATE TABLE - Creates a TableINSERT - Creates a row
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Creation
CREATE DATABASE - Creates a new Schema
CREATE TABLE - Creates a TableINSERT - Creates a row
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Creation
CREATE DATABASE - Creates a new SchemaCREATE TABLE - Creates a Table
INSERT - Creates a row
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Creation
CREATE DATABASE - Creates a new SchemaCREATE TABLE - Creates a TableINSERT - Creates a row
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Read
SELECT - Selects matching rowsSELECT is the most complex of the statements, it’s wheremost of the work is done!
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Read
SELECT - Selects matching rows
SELECT is the most complex of the statements, it’s wheremost of the work is done!
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Read
SELECT - Selects matching rowsSELECT is the most complex of the statements, it’s wheremost of the work is done!
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Modifying Data
UPDATE - Change values on matching rowsDELETE - Delete matching rows
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Modifying Data
UPDATE - Change values on matching rows
DELETE - Delete matching rows
Robert Lowe DBMS - Introduction to MySQL
Overview of MySQLIntroduction to SQL
Modifying Data
UPDATE - Change values on matching rowsDELETE - Delete matching rows
Robert Lowe DBMS - Introduction to MySQL