Docsity

Managing MySQL Tables: Creating, Dropping, Indexing & Altering Tables, Papers of Database Management Systems (DBMS)

Partial preview of the text

Download Managing MySQL Tables: Creating, Dropping, Indexing & Altering Tables and more Papers Database Management Systems (DBMS) in PDF only on Docsity!

Managing Data

in MySQL

Altering Tables

  • MySQL enables you to create tables, drop (remove) them, and

change their structure with the CREATE TABLE , DROP

TABLE ,and ALTER TABLE statements.

  • The CREATE INDEX and DROP INDEX statements enable you

to add or remove indexes on existing tables. The following

sections provide the details for these statements

Altering Tables

Storage Engine Characteristics

MySQL Storage Engines

Storage Engines Description ARCHIVE Archival storage (no modification of rows after insertion) BLACKHOLE Engine that discards writes and returns empty reads CSV Storage in comma-separated values format EXAMPLE Example (“stub”) storage engine Falcon Transactional engine (MySQL 6.0 ) FEDERATED Engine for accessing remote tables

Altering Tables

Storage Engine Characteristics

MySQL Storage Engines

Storage Engines Description InnoDB Transactional engine with foreign keys MEMORY In-memory tables MERGE Manages collections of MyISAM tables MyISAM The default storage engine NDB The engine for MySQL Cluster

Altering Tables

Checking Which Storage Engines Are Available

  • The engines actually available to you for a given server depend on your version of MySQL, how the server was configured at build time, and the options with which it was started
  • To see which storage engines the server knows about, use the SHOW ENGINES statement. It provides information that helps you determine the answers to questions such as which transactional storage engines are available. SHOW ENGINES\G
  • To check for engines in your server that support transaction you can use this SELECT ENGINE FROM INFORMATION_SCHEMA.ENGINES WHERE TRANSACTIONS = 'YES';

Altering Tables

Table Representation on Disk

  • Each time you create a table, MySQL creates a disk file that contains the

table’s format

  • The format file has a basename that is the same as the table name and an .frm extension.
  • The server creates the file in the database directory for the database that the table belongs to.
  • The .frm file is an invariant because there is one for every table,no matter which storage engine manages the table.
  • The name of a table as used in SQL statements might differ from the table-name part of the associated .frm file if the name contains characters that are problematic in filenames.

Altering Tables

Table Files Created by Storage Engines Storage Engine Files on Disk MyISAM .MYD (data), .MYI (indexes MERGE .MRG (list of constituent MyISAM table names) InnoDB .ibd (data and indexes) ARCHIVE .ARZ (data), .ARM (metadata) CSV .CSV (data), .CSM (metadata)

Altering Tables

Table Representation on Disk

  • For some storage engines,the format file is the only file specifically

associated with a particular table.

  • Other engines may store table content elsewhere than on disk, or may

use one or more tablespaces (storage areas shared by multiple tables)

  • MEMORY table contents are stored in memory, not on disk.
  • By default, InnoDB stores table data and indexes in its shared tablespace. That is,all InnoDB table contents are managed within a shared storage area, not within files specific to a particular table.InnoDB creates .ibd files only if you configure it to use individual per-table tablespaces.

Altering Tables

the features and behavior of selected MySQL storage engines.

The MyISAM Storage Engine

  • The MyISAM storage engine is the default engine in MySQL
  • MyISAM provides key compression.
    • It uses compression when storing runs of successive similar string index values.
    • MyISAM also can compress runs of similar numeric index values because numeric values are stored with the high byte first. (Index values tend to vary faster in the low-order bytes,so high-order bytes are
    • more subject to compression.)
    • To enable numeric compression,use the PACK_KEYS=1 option when creating a MyISAM table.

Altering Tables

the features and behavior of selected MySQL storage engines.

The MyISAM Storage Engine

  • MyISAM provides more features for AUTO_INCREMENT columns than do

other storage engines

  • MyISAM supports full-text searching through the use of FULLTEXT

indexes.

  • MyISAM supports spatial data types and SPATIAL indexes.

Altering Tables

the features and behavior of selected MySQL storage engines.

The MERGE Storage Engine
  • MERGE tables provide a means for grouping a set of MyISAM tables into a single
logical unit.
  • Querying a MERGE table in effect queries all the constituent tables.
    • One advantage of this is that you can exceed the maximum table size allowed by the filesystem for individual MyISAM tables.
  • The tables that make up a MERGE table must all have the same structure. This
means that the columns in each table must be defined with the same names and
types in the same order, and the indexes must be defined in the same way and in
the same order. It is allowable to mix compressed and uncompressed tables

Altering Tables

the features and behavior of selected MySQL storage engines.

The MEMORY Storage Engine

  • The MEMORY storage engine uses tables that are stored in memory and

that have fixed length rows, two properties that make them very fast.

  • MEMORY tables are temporary in the sense that their contents disappear

when the server terminates.

  • a MEMORY table still exists when the server restarts ,but will be empty
  • In contrast to temporary tables created with CREATE TEMPORARY

TABLE ,MEMORY tables are visible to other clients.

Altering Tables

the features and behavior of selected MySQL storage engines.

The InnoDB Storage Engine

  • The InnoDB storage engine was originally developed by Innobase Oy,

which subsequently was acquired by Oracle.

  • InnoDB offers these features:
    • Transaction-safe tables with commit and rollback. Savepoints can be created to enable partial rollback.
    • Automatic recovery after a crash.
    • Foreign key and referential integrity support, including cascaded delete and update.

Altering Tables

the features and behavior of selected MySQL storage engines.

The InnoDB Storage Engine

  • InnoDB offers these features:
    • Row-level locking and multi-versioning for good concurrency performance under query mix conditions that include both retrievals and updates.
    • By default, InnoDB manages tables within a single shared tablespace, rather than by using table-specific files like most other storage engines. The tablespace can consist of multiple files and can include raw partitions. The InnoDB storage engine, in effect, treats the tablespace as a virtual filesystem within which it manages the con tents of all InnoDB tables. Tables thus can exceed the size allowed by the filesystem for individual files. You can also configure InnoDB to use individual tablespaces,one per table. In this case,each table has an .ibd file in its database directory.