falando de mysql

32
Falando de

Upload: marcio-junior

Post on 31-May-2015

365 views

Category:

Technology


1 download

DESCRIPTION

Curso de MySQL ministrado por mim aqui na empresa onde trabalho. http://www.mysqldownload.com.br

TRANSCRIPT

Page 1: Falando de MySQL

Falando de

Page 2: Falando de MySQL

Arquitetura MySQL

Query Cache

Client Program

C client API

Query Parsing

Optimization

Execution

Storage Engine(MyISAM – InnoDB –

Memory – CSV – etc…)

Page 3: Falando de MySQL

Data Types

O Numeric – Integers, Floating-Point, Fixed-Point and Bit-field

O Character – Text stringsO Binary – Binary data stringsO Temporal – Time and Dates

Page 4: Falando de MySQL

Numeric - IntegersData Types

Page 5: Falando de MySQL

Numeric - Floating-PointData Types

Page 6: Falando de MySQL

Numeric - Fixed-Point and Bit-field

• Decimal(p,s) – 4 Bytes per 9 digits – P: Max 65 - S: Max 30

• BIT(n)– 1Byte per 8 digits

Data Types

Page 7: Falando de MySQL

CharacterData Types

Page 8: Falando de MySQL

BinaryData Types

Page 9: Falando de MySQL

TemporalData Types

Page 10: Falando de MySQL

Storage Engine

O MyISAMO InnoDBO MemoryO ArchiveO BlackHoleO CSV

Page 11: Falando de MySQL

MyISAMStorage Engine

O Represents each table using three files: O A format file--stores the definition of the table structure (mytable.frm) O A data file--stores the contents of table rows (mytable.MYD) O An index file that stores any indexes on the table (mytable.MYI)

O The most flexible AUTO_INCREMENT column handling of all the storage engines O Can be converted into fast, compressed, read-only tables to save space O Manages contention between queries for MyISAM table access using table-level

locking O Supports FULLTEXT searching and spatial data types O Supports for geometric spatial extensions O The table storage format is portable, so table files can be copied directly to another

host and used by a server there O Can improve performance by limiting table size to a certain number of rows O When loading data into an empty table, updating of non-unique indexes can be

disabled and then reenabled after loading the data O  Tables take up very little space

Page 12: Falando de MySQL

MyISAMStorage Engine

PROs O Max. tablesize 65535 TB (unless constrained by OS or file system) O Low storage cost (efficient storage handling) O Support for B-Tree, FullText, and spatial indexes O Very fast insert performance O Very fast query performance O Maintains accurate count of number of rows stored in table (SELECT

COUNT(*) very fast). O Support for prefix-length index keys

CONs O No support for transactionsO Table-level locking O No crash recovery O Blocking online backupO No support for foreign key constraints

Page 13: Falando de MySQL

InnoDBStorage Engine

O Each InnoDB table is represented on disk by an .frm format file in the database directory, as well as data and index storage in the InnoDB tablespace: O The tablespace is a set of files (1 or more) that InnoDB uses to store data and indexes O By default, InnoDB uses a single tablespace that is shared by all tables O Table sizes can exceed the maximum file size allowed by the filesystem O Can configure InnoDB to create each table with its own tablespace

O Supports transactions, with COMMIT and ROLLBACK O Provides full ACID compliance O Provides auto-recovery after a crash of the MySQL server O Row level locking with MVCC (Multi-Versioning Concurrency Control) and non-

locking reads O Supports foreign keys and referential integrity, including cascaded deletes and

updatesO Supports consistent and online logical backup

Page 14: Falando de MySQL

InnoDBStorage Engine

O TableSpaceO --innodb-file-per-table

Page 15: Falando de MySQL

InnoDBStorage Engine

PROsO ACID-compliant O Support for crash recovery O High storage limit (64TB per tablespace, practically limited by file system) O Unlimited row-level locking O Support for foreign key constraints O MVCC support O Clustered, B+Tree index support O MySQL-supplied online, non-blocking backup O Advanced memory cache mechanisms

CONsO No full-text or spacial index supportO Faster online logical backup utility an add-on cost option (Hot Backup)O Requires more disk and memory resources

Page 16: Falando de MySQL

MemoryStorage Engine

O Each table is represented on disk by an .frm format file in the database directory. Table data and indexes are stored in memory

O In-memory storage results in very fast performance O Contents do not survive a restart of the server (structure

survives, but table contains zero rows) O Limited by max_heap_table_size so they do not get too

large O MySQL manages query contention using table-level locking.

Deadlock cannot occur. O Cannot contain TEXT or BLOB columns O Can use different character sets for different columns

Page 17: Falando de MySQL

MemoryStorage Engine

PROsO Extremely fast read and write operations O Support for tree and hash indexes O Main memory database management

CONsO Data is not persistent between server shutdown’s O No support for transactionsO No support for foreign keysO No full-text or spatial index support O Table level lockingO Cannot store BLOB or Text data

Page 18: Falando de MySQL

ArchiveStorage Engine

O Each table is represented on disk only by an .frm format file in the database directory.

O Data and metadata files have extensions of .ARZ and .ARM, respectively.

O Does not support indexes. O Supports INSERT and SELECT, but not DELETE,

REPLACE, or UPDATE. O Supports ORDER BY operations, BLOB columns, and

basically all but spatial data types. O Uses row-level locking. O Supports AUTO_INCREMENT columns.

Page 19: Falando de MySQL

CSVStorage Engine

O Each table is represented on disk by an .frm format file in the database directory.

O Data file (plain text) has a .csv extension, and is in comma-separated values format.

O Metadata files are created with the extension .csm. O Does not support indexes. O Data can be copied from the database directly and

transferred to a client such as a spreadsheet application, and the table may be opened in a spreadsheet format.

Page 20: Falando de MySQL

BlackHoleStorage Engine

O Verification of dump file syntax. O Measurement of the overhead from binary

logging, by comparing performance using BLACKHOLE with and without binary logging enabled.

O BLACKHOLE is essentially a "no-op" storage engine, so it could be used for finding performance bottlenecks not related to the storage engine itself.

Page 21: Falando de MySQL

Eventos

Page 22: Falando de MySQL

EventosDELIMITER $$CREATE EVENT copyProcesslist2ON SCHEDULE EVERY 1 SECONDSTARTS '2012-03-31 10:00:00'ENDS '2012-04-01 10:00:00'ON COMPLETION PRESERVEDISABLEDO BEGIN REPLACE INTO world.processlist SELECT * FROM information_schema.processlist;

END;END$$

Page 23: Falando de MySQL

Stored ProceduresDELIMITER $$CREATE PROCEDURE `principal`.`calculaSaldo` (IN conta INT )BEGIN SELECT count(saldo) FROM extrato WHERE idConta = conta;END$$

Page 24: Falando de MySQL

Triggers

Page 25: Falando de MySQL

Security

Page 26: Falando de MySQL

Security

Page 27: Falando de MySQL

Administrative privilegesSecurity

Page 28: Falando de MySQL

Database privilegesSecurity

Page 29: Falando de MySQL

Table privilegesSecurity

Page 30: Falando de MySQL

Column privilegesSecurity

Page 31: Falando de MySQL

Routine privilegesSecurity

Page 32: Falando de MySQL

Grant and RevokeSecurity

O ALL and ALL PRIVILEGES are shorthand for "all privileges except GRANT OPTION." That is, they are shorthand for granting all privileges except the ability to give privileges to other accounts.