falando de mysql
DESCRIPTION
Curso de MySQL ministrado por mim aqui na empresa onde trabalho. http://www.mysqldownload.com.brTRANSCRIPT
Falando de
Arquitetura MySQL
Query Cache
Client Program
C client API
Query Parsing
Optimization
Execution
Storage Engine(MyISAM – InnoDB –
Memory – CSV – etc…)
Data Types
O Numeric – Integers, Floating-Point, Fixed-Point and Bit-field
O Character – Text stringsO Binary – Binary data stringsO Temporal – Time and Dates
Numeric - IntegersData Types
Numeric - Floating-PointData Types
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
CharacterData Types
BinaryData Types
TemporalData Types
Storage Engine
O MyISAMO InnoDBO MemoryO ArchiveO BlackHoleO CSV
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
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
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
InnoDBStorage Engine
O TableSpaceO --innodb-file-per-table
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
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
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
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.
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.
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.
Eventos
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$$
Stored ProceduresDELIMITER $$CREATE PROCEDURE `principal`.`calculaSaldo` (IN conta INT )BEGIN SELECT count(saldo) FROM extrato WHERE idConta = conta;END$$
Triggers
Security
Security
Administrative privilegesSecurity
Database privilegesSecurity
Table privilegesSecurity
Column privilegesSecurity
Routine privilegesSecurity
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.