Class #3 of the MySQL class is scheduled for this Monday, May 16 at 7:00pm at CalTek and will cover the Storage Engines, DDL (Data Definition Language), Primary Keys, Columns Types, and Indexes.
*Complete syllabus for Class #3 are continued in the further reading section.*
_Instructor:_
*David Rolston :: david_AT_gizmola_(dot)_com*
_Class Contact:_
*Sharon Lake :: sharon_AT_linuxchixla_(dot)_org*
_Lab Help:_
*Steve Glasser :: steve_AT_fpig_(dot)_net*
*_CLASS #3 SYLLABUS_*
Class 3 – Data Definition Language.
(Chapter 4 / MySQL-M 1.2.4, 1.5.6.1, 3.3.2, 3.6.9, 11, 13.2, 13.5.4, 14, 15)
[NOTE: MySQL-M 7 covers optimization and how to use INDEXES effectively. Optimization techniques are not covered in this class.]
_20% exam material_
- General Database and Table Properties
- MySQL associates each database on the server with a directory under the data directory. The directory has the same name as the database it represents. The directory contains all the files associated with the database, i.e., indexes and tables.
- Databases cannot be nested, i.e., one database cannot contain another.
- Tables consist of rows and columns. A table can be empty, i.e., it can have 0 rows,but it must have at least one column.
- Every table is associate with a format file in the database directory. The format file name is the same as the table name followed with a .frm extension. Depending on the storage engine MySQL might create additional files
- MyISAM storage engine creates data and index file(s) named tablename.MYD and tablename.MYI respectively
- InnoDB storage engine creates the .frm file, but stores the data and index information in an InnoDB tablespace
- Storage Engine and Table Types
- MyISAM Tables
- represented on disk with .frm format file, an .MYD datafile and an .MYI index file
- most flexible AUTO-INCREMENT column handling
- can be set up to handle MERGE tables
- can be converted to compressed, read-only tables
- supports FULL TEXT searching
- uses table level locking for query contentions and write queries.
- InnoDB Tables
- represented on disk with .frm format file in database directory, as well as data and index storage in the InnoDB tablespace. The table space is shared by all InnoDB tables.
- Supports transactions with full ACID compliance
- provides auto-recovery after server or host crash
- supports foreign keys and referential integrity, including cascaded deletes and updates
- uses multi-versioning and row-level locking for query contentions.
- MERGE Tables
- a MERGE table is a collection of identically structured MyISAM tables represented on disk by an .frm format file and an .MRG file located in the database directory
- a query on a MERGE table acts as a query on all the MyISAM tables of which it consists.
- A MERGE table creates a logical entity that can exceed the maximum MyISAM table size
- BDB (Berkeley DB) Tables (Note: BDB storage engine not enabled in LAMPsig/Knoppix LiveCD installation)
- represented on disk by an .frm format file and a .db file that stores data and index information located in database directory.
- Supports transactions with full ACID compliance
- uses page-level locking for query contention.
- HEAP (Memory) Tables
- represented on disk by a .frm format file in database directory. Table data and indexes are stored in memory
- In-memory storage results in fast performance
- HEAP table contents do not survive a restart of the server. The structure survives, but it contains 0 data rows after a restart
- Limits on Database Components
- MySQL doesn't place limits on number of databases, but the OS or filesystem might due to limits on number of sub-directories allowed in filesystem tree.
- MySQL databases are represented on disk in sub-directories
- MySQL doesn't place limits on number of files in directory, tho the OS or filesystem might.
- MyISAM tables are represented on disk in files under the database subdirectory
- MySQL does place limits on size of individual tables. Techniques around this limitation would include:
- MERGE tables (for MyISAM storage engine)
- RAID setup (for datafiles only as index tables are stored in a single file)
- Convert MyISAM tables to InnoDB tables as InnoDB allows for larger datafiles.
- For OS or filesystem limitations see if OS dependent adjustments are possible.
- Identifier Syntax. Identifiers identify a specific database elements, e.g, databases, tables, table columns, aliases, and (sometimes) indexes.
- Legal Characters
- Qualifiers for Table and Column Names. Sometimes qualifiers are necessary to resolve ambiguity.
- SELECT * FROM Country;
SELECT * FROM world.Country; - SELECT Name FROM Country;
SELECT Country.Name FROM Country;
SELECT world.Country.Name FROM world.Country;
- CREATE and DROP DATABASE
- CREATE TABLE
- Syntax
- Temporary
- DROP TABLE
- ALTER TABLE
- Adding and Dropping Columns
- Modifying Existing Columns
- Renaming a Table
- Specifying Multiple Alterations
- Creating and Dropping Indexes
- Four types of Indexes
- non-unique index
- UNIQUE
- PRIMARY KEY
- FULL TEXT
- Defining at Table-Creation Time
- Creating and Using Primary Keys
- Modifying Indexes of Existing Tables
- Column Types
- Numeric / Integer
- TINYINT
- SMALLINT
- MEDIUMINT
- INT
- BIGINT
- Numeric / Floating-Point and Fixed-Decimal
- FLOAT
- DOUBLE
- DECIMAL
- String
- Binary and Nonbinary String Characteristics
- CHAR
- VARCHAR
- BLOB
- TEXT
- ENUM
- SET
- Date and Time
- DATE
- TIME
- DATETIME
- TIMESTAMP
- YEAR
- Column Options
- UNSIGNED
- ZEROFILL
- AUTO_INCREMENT
- BINARY
- NULL and NOT NULL
- DEFAULT
- PRIMARY KEY and UNIQUE
- Using AUTO_INCREMENT
- Automatic Type Conversion and Value Clipping
- DESCRIBE and SHOW to display table structures