mysql for the oracle dba - object management

23
4a-1 Copyright 2008 MySQL Inc MySQL - The Best Online Database for modern applications 4a. MySQL Object Management Version 1.2 4a. MySQL Object Management for the Oracle DBA Ronald Bradford Senior Consultant MySQL Inc January 2008

Upload: ronald-bradford

Post on 15-May-2015

4.276 views

Category:

Technology


3 download

DESCRIPTION

Example section on MySQL for the Oracle DBA 1 day bootcamp.In object management we look at the key SQL objects including what differs with Oracle and what is Oracle specific functionality.We also look at the MySQL data dictionary, the INFORMATION_SCHEMA

TRANSCRIPT

Page 1: MySQL for the Oracle DBA - Object Management

4a­1Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

4a. MySQL Object Management

for the Oracle DBA

Ronald BradfordSenior Consultant

MySQL IncJanuary 2008

Page 2: MySQL for the Oracle DBA - Object Management

4a­2Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

Agenda

GOAL: Creating and Managing MySQL Objects  SQL Object Types Creating Objects Managing Objects MySQL Data Dictionary

Page 3: MySQL for the Oracle DBA - Object Management

4a­3Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

 

SQL Object Types

Page 4: MySQL for the Oracle DBA - Object Management

4a­4Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

Object Types User Database     (Schema) Tablespace / Data File Table / Column Index View Trigger Stored Procedure Stored Function User Defined Function (UDF)

No SequencesNo SnapshotsNo Synonyms

Page 5: MySQL for the Oracle DBA - Object Management

4a­5Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

Users

There is no concept of user ownership within MySQL  All objects are part of a database (or 'schema')  Users only have object privileges assigned to them 

Page 6: MySQL for the Oracle DBA - Object Management

4a­6Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

Table / Column

Table Name is case sensitive (by default) Reserved Words are permitted (appropriately quoted)

http://dev.mysql.com/doc/refman/5.1/en/reserved­words.html

Page 7: MySQL for the Oracle DBA - Object Management

4a­7Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

Indexes

Default Index type is BTREE Memory has HASH & BTREE Indexes MyISAM has a FULLTEXT Index

Page 8: MySQL for the Oracle DBA - Object Management

4a­8Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

Views

Updatable and non­updatable views supported view and table names must be unique DEFINER clause allows view to run as the calling user, 

or another defined user View restrictions

cannot contain a subquery in the FROM clause. cannot refer to system or user variables. cannot refer to prepared statement parameters. Within a stored routine, the definition cannot refer to routine 

parameters or local variables.

Page 9: MySQL for the Oracle DBA - Object Management

4a­9Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

Views View restrictions (cont)

Any table or view referred to in the definition must exist. However after creation, underlying objects can be dropped or modified. View is not invalidated, but will throw error on usage.

The definition cannot refer to a TEMPORARY table You cannot create a TEMPORARY view. The tables named in the view definition must already exist. You cannot associate a trigger with a view.

View algorithms MERGE TEMPTABLE UNDEFINED

Supports WITH CHECK OPTION Do not support Materialized Views

Page 10: MySQL for the Oracle DBA - Object Management

4a­10Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

Triggers

DML triggers only ­ no system triggers [BEFORE | AFTER] [INSERT | UPDATE | DELETE] Only one of each trigger type supported FOR EACH ROW, no FOR EACH STATEMENT No INSTEAD OF No WHEN Condition NEW.col and OLD.col syntax CALL statement for SP not permitted No statements that implicitly or explicitly COMMIT | 

ROLLBACK 

Page 11: MySQL for the Oracle DBA - Object Management

4a­11Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

Stored Procedures

PL/PSM (Persistent Stored Modules)  Non scrollable, read only cursors Support for most loop types (FOR loops not yet) DEFINER clause allows stored procedure to run as the 

calling user, or another defined user No packages support No anonymous blocks No concept of dependency within MySQL Stored procedures are not required for high 

performance within MySQL

Page 12: MySQL for the Oracle DBA - Object Management

4a­12Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

User Defined Functions (UDF) Added as Object Files Compiled and available on permanent basis

mysql> create function logger returns integer soname 'syslogudf.so';mysql> select logger('logging from ' + version());

http://dev.mysql.com/doc/refman/5.0/en/adding­functions.html

Page 13: MySQL for the Oracle DBA - Object Management

4a­13Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

MySQL Create Object Limitations

No online ALTER Table No online Add Tablespace Data File

Online Add Index (5.1) Online Add Enum Value (5.1) Online Add Column (5.1 ­ MyISAM)

Page 14: MySQL for the Oracle DBA - Object Management

4a­14Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

MySQL Auto Increment

Replacement for SEQUENCE

Limitations Only one per table No System wide concept No Get Next capability Get Value after Insert with LAST_INSERT_ID() No required in INSERT, or NULL can be used No persistence of true max value used across restart

exists in Falcon 6.0

http://dev.mysql.com/doc/refman/5.0/en/example­auto­increment.html

Page 15: MySQL for the Oracle DBA - Object Management

4a­15Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

 

MySQL Data Dictionary

Page 16: MySQL for the Oracle DBA - Object Management

4a­16Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

MySQL Data Dictionary

Two Present Sources Privilege/System Tables ­  'mysql' database  Information Schema

Page 17: MySQL for the Oracle DBA - Object Management

4a­17Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

'mysql' database Privileges (host, db ,user, tables_priv, columns_priv,procs_priv) Help (help_category, help_keyword, help_relation, help_topic) Time zones (time_zone, time_zone_name, 

time_zone_leap_second, time_zone_transition, time_zone_transition_type)

Procedure & Function (proc, func)

Page 18: MySQL for the Oracle DBA - Object Management

4a­18Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

INFORMATION_SCHEMA5.0 SCHEMATA, TABLES, COLUMNS, TABLE_CONSTRAINTS, 

VIEWS, STATISTICS USER_PRIVILEGES, 

SCHEMA_PRIVILEGES,TABLE_PRIVILIGES, COLUMN_PRIVILEGES

CHARACTER_SETS, COLLATIONS, COLLATION_CHARACTER_SET_APPLICIBILITY

ROUTINES, PROFILING5.1 KEY_COLUMN_USAGE,PLUGINS,ENGINES,PARTITIONS,EVENT

S,FILES, REFERENTIAL_CONSTRAINTS, PROCESSLIST, GLOBAL_STATUS, 

SESSION_STATUS,GLOBAL_VARIABLES,SESSION_VARIABLES 6.0 FALCON_

Page 19: MySQL for the Oracle DBA - Object Management

4a­19Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

 

 

Page 20: MySQL for the Oracle DBA - Object Management

4a­20Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

INFORMATION_SCHEMA ExamplesTable Disk Size for given schema 

select table_name, table_rows, avg_row_length,       data_length/1024/1024 as data_mb,        index_length/1024/1024 as index_mb from information_schema.tables where table_schema='dbname'order by 4 desc;

Page 21: MySQL for the Oracle DBA - Object Management

4a­21Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

INFORMATION_SCHEMA Examples 

SELECT TABLE_SCHEMA, SUM((DATA_LENGTH + INDEX_LENGTH) / (1024 * 1024)) AS SIZE_MB  FROM INFORMATION_SCHEMA.TABLES

GROUP BY TABLE_SCHEMA ORDER BY SIZE_MB DESC

SELECT ROUTINE_TYPE, ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA='dbname';

SELECT TRIGGER_NAME,EVENT_MANIPULATION,EVENT_OBJECT_TABLE, ACTION_STATEMENT FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_SCHEMA='dbname';

SELECT CONCAT('DROP TABLE ',table_name,';')INTO OUTFILE '/sql/drop_tables.sql'FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 

'dbname';

Page 22: MySQL for the Oracle DBA - Object Management

4a­22Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

INFORMATION_SCHEMA Examples 

SELECT s.schema_name, CONCAT(IFNULL(ROUND((SUM(t.data_length)+           SUM(t.index_length))/1024/1024,2),0.00),'Mb') total_size,  CONCAT(IFNULL(ROUND(((SUM(t.data_length)+SUM(t.index_length))­SUM(t.data_free))/1024/1024,2),0.00),'Mb') data_used,

CONCAT(IFNULL(ROUND(SUM(data_free)/1024/1024,2),0.00),'Mb') data_free,

IFNULL(ROUND((((SUM(t.data_length)+SUM(t.index_length))­   SUM(t.data_free))/((SUM(t.data_length)+SUM(t.index_length)))*100),2),0) pct_used,       COUNT(table_name) total_tables

FROM information_schema.schemata s

LEFT JOIN information_schema.tables t ON s.schema_name = t.table_schema

WHERE s.schema_name != 'information_schema'

GROUP BY s.schema_name  ORDER BY pct_used DESC\G

Page 23: MySQL for the Oracle DBA - Object Management

4a­23Copyright 2008 MySQL Inc MySQL ­ The Best Online Database for modern applications

4a. MySQL Object ManagementVersion 1.2

 

Questions?