mysql for oracle developers
DESCRIPTION
MySQL for Oracle Developers and the companion MySQL for Oracle DBA's were two presentations for the 2006 MySQL Conference and Expo. These were specifically designed for Oracle resources to understand the usage, syntax and differences between MySQL and Oracle.TRANSCRIPT
MySQL for Oracle Developers
Ronald Bradfordwww.arabx.com.au
Version 1.2 20 April 2006
Slide: 2
MySQL for Oracle Developers
MySQL Introduction
Solid peneration in open source community
LAMP Stack
Large number of open source projects
Included by default in most Linux distros
Slide: 3
MySQL for Oracle Developers
Purpose of Presentation
Maximise existing Oracle skill set
Preparation for management requests
Open Source introduction
Terminology/Product Knowledge Transfer
Slide: 4
MySQL for Oracle Developers
My Background
16 years in Database Design Experience (1989)
10 years Oracle Experience (1996)
7 years MySQL Experience (1999)
Active in MySQL, Java, XP, Oracle User Groups
INFO
Slide: 5
MySQL for Oracle Developers
Presentation Conventions
Associated Talk for DBA's
Oracle Specific Syntax
ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
MYSQL_HOME=/usr/lib/mysql (*) MYSQL_DATA=/var/lib/mysql (*)
(*) For RPM install. Will differ depending on Distro, or .tar.gz install
MySQL for Oracle DBA's
Oracle Command/Syntax
Slide: 6
MySQL for Oracle Developers
Product Comparision
Current Versions at March 2006 (used in examples)
MySQL 5.0 GA (5.0.20) Standard/Maxhttp://www.mysql.com/products/database/
Oracle 10g Release 2 Express Edition (10.2.0.1)http://www.oracle.com/technology/products/database/xe
Slide: 7
MySQL for Oracle Developers
Product Comparision
Other Production Versions
Oracle 10g Release 2 (PE, SE1, SE, EE)Oracle 9i, 8i, 7.3MySQL 4.1, 4.0, 3.23MySQL MaxDB 7.6
INFO
Slide: 8
MySQL for Oracle Developers
Product Comparision
Development Versions
MySQL 5.1 (currently beta 5.1.7)MySQL 5.2
Open Source Availability
5.1
OS
Slide: 9
MySQL for Oracle Developers
Oracle Developer Environments
Oracle JDeveloper Java Application
J2EE Application Development Framework (ADF)
Application Express (HTMLDB)
Oracle Forms 4.5, 6i, 9i,10g
PHP (Zend Core)
INFO
Slide: 10
MySQL for Oracle Developers
Forrester Research
December 29, 2004Open Source Databases Come Of Age
Slide: 11
MySQL for Oracle Developers
Technical Resources
ORACLEotn.oracle.com
forums.oracle.com
www.oracle.com/support
education.oracle.com
www.oracle.com/education/certification/
blogs.oracle.comwww.oracle.com/technology/community/user_groups
www.oracle.com/technology/documentation
www.orafaq.com
MYSQLdev.mysql.com forge.mysql.com
forums.mysql.com
www.mysql.com/network
www.mysql.com/training
www.mysql.com/certification
www.planetmysql.org
dev.mysql.com/usergroupswww.mysql.com/doc
dev.mysql.com/techresources/faq.html
Slide: 12
MySQL for Oracle Developers
MySQL 5.0 For Developers (5 days)
http://www.mysql.com/training/workshops/mysql_dev.html
ObjectivesDescribe the MySQL client/server architectureUnderstand the steps necessary to invoke MySQL client programsUtilize the generalpurpose mysql client program to run queries and retrieve resultsPerform queries and analysis of data utilizing the MySQL Query Browser graphical user interfaceExplain the MySQL connectors that provide connectivity for client programsSelect the best data type for representing information in MySQLManage the structural characteristics of your databasesManage the structural characteristics of the tables within your databasesUtilize the SELECT statement to retrieve information from database tables
INFO
Slide: 13
MySQL for Oracle Developers
MySQL 5.0 For Developers
Utilize expressions in SQL statements to retrieve more detailed informationUtilize SQL statements to modify the contents of database tablesWrite join expressions in your SQL statements to obtain information from multiple tablesUtilize subqueries in your SQL statementsCreate views utilizing SELECT statements to produce "virtual tables" of specific dataPerform bulk data import and export operationsCreate user defined variables, prepared statements and stored routinesCreate and manage triggersUse the INFORMATION_SCHEMA database to access metadataDebug MySQL applicationsConfigure and Optimize MySQL
INFO
Slide: 14
MySQL for Oracle Developers
MySQL Installation
Two Initial Databasesmysqltest
http://dev.mysql.com/doc/refman/5.0/en/installing.html
Access Privilegesroot
http://dev.mysql.com/doc/refman/5.0/en/privilege_system.html
MySQL for Oracle DBA's
INFO
Slide: 15
MySQL for Oracle Developers
Configuration/Log Files
my.cnf$MYSQL_HOME/my.cnf, /etc/my.cnf
Database Log$MYSQL_DATA/`hostname`.err
N/AUser Security (host)
$ORACLE_HOME/dbs/init.ora
$ORACLE_HOME/network/admin/tnsnames.ora
.../admin/XE/bdump/alert_XE.log
MySQL for Oracle DBA's
INFO
Slide: 16
MySQL for Oracle Developers
Terminology
ORACLEDatabase (files)
Database Instance (memory)Schema User
UserTable Space
MYSQLDatabase Server InstanceDatabase Server InstanceDatabaseUser
Table Space
Storage Engine
INFO
Slide: 17
MySQL for Oracle Developers
MySQL Sample Database
Sakila Sample DatabaseAnnounced at this Conference
Showcases Current MySQL features
http://forums.mysql.com/list.php?121
scott/tiger
Slide: 18
MySQL for Oracle Developers
MySQL Sample Database INFO
Slide: 19
MySQL for Oracle Developers
Command Line SQL
mysqlhttp://dev.mysql.com/doc/refman/5.0/en/mysql.html
Command line syntax
Navigation commands
mysql u[username] p[password] h[host] [dbname]mysql p [dbname]mysql help
help or ? clear \cquit \q edit; \g \G tee [file]
sqlplus system/manager@netname
Slide: 20
MySQL for Oracle Developers
Immediate SQL Differences
DUALSYSDATEDECODE()ROWNUMNVLJOIN (+) Syntax
Date FunctionsSequences Data TypesNaming Standards
Case Sensitivity Reserved Words
Slide: 21
MySQL for Oracle Developers
Case Sensitivity
DDL Structure Names as Case sensitivee.g. CREATE TABLE FilmActor (...);Operating System Dependent
LIKE for Data is Case insensitivee.g. SELECT title FROM film WHERE title LIKE 'A%'Returns rows starting with 'ALIEN' and 'alien'
BINARY DDL syntaxe.g. title VARCHAR(100) NOT NULL BINARY,
Slide: 22
MySQL for Oracle Developers
DLL Structure Syntax
Escaped Reserved Words are allowede.g. CREATE TABLE `group` (...);e.g. CREATE TABLE “insert” (...); * sql_mode
Tables/Columns/Triggers/Stored ProceduresSpace and other special characters allowed
Operating System Dependente.g. CREATE TABLE `My Table Name` (...);
Slide: 23
MySQL for Oracle Developers
Sequences Replacement
AUTO_INCREMENTe.g. id INT NOT NULL AUTO_INCREMENT,
Must be tied to a [table].[column]Only one per tableNo system wide capabilityLAST_INSERT_ID()No get next capability
seq.CURRVAL
CREATE SEQUENCE seq;
seq.NEXTVAL
Slide: 24
MySQL for Oracle Developers
Optional Table Name
SELECT 1+1No Table Required
Provided for Oracle Compatibilitye.g. SELECT 1+1 FROM DUAL
e.g. SELECT DUMMY FROM DUAL *** Fails
DUAL
Slide: 25
MySQL for Oracle Developers
Transactions
MySQL provides ACID compliant transactions
XA transactions (Distributed Transaction Processing)
http://dev.mysql.com/doc/refman/5.0/en/xa.html
Supports transactional and nontransactional databases
Satisfy both missioncritical 24/7 usage and heavy Web or logging usage
Slide: 26
MySQL for Oracle Developers
Transactions
By default, SQL commands are autocommitted
Transaction support with appropiate Storage EnginesSTART TRANSACTION / BEGIN [WORK]ROLLBACK [WORK] / COMMIT [WORK]SET AUTOCOMMIT = {0 | 1};SAVEPOINT / ROLLBACK [WORK] TO SAVEPOINTSET TRANSACTION (Isolation Level)
http://dev.mysql.com/doc/refman/5.0/en/transactionalcommands.html
Slide: 27
MySQL for Oracle Developers
Storage Engines
MyISAM
MERGE
InnoDB
BDB
MEMORY
ARCHIVE
FEDERATED
NDB (Cluster)
CSV
BLACKHOLE
Example
http://dev.mysql.com/doc/refman/5.0/en/storageengines.html
INFO
Slide: 28
MySQL for Oracle Developers
Storage Engines
http://www.mysql.com/whymysql/whitepapers/mysql_wp_pluggable.phpMySQL 5.0's Pluggable Storage Engine Architecture
High
INFO
Slide: 29
MySQL for Oracle Developers
Locking
Storage Engine DependentTable Level Locking (MyISAM, Memory)Page Level Locking (BDB)Row Level Locking (InnoDB, Archive, NDB)
LOW_PRIORITY, HIGH_PRIORITY changes WRITE/READ Lock Handling
Slide: 30
MySQL for Oracle Developers
Locking
InnoDB
rowlevel locking
multiversioning
nonlocking repeatable reads
all four SQL standard isolation levels
Most Commonly Used Transactional
Storage Engine
Slide: 31
MySQL for Oracle Developers
NULL
[column] IS NULL, [column] IS NOT NULL
IFNULL([value],'')
ISNULL([value])
COALESCE([value],[value],[value])
NVL(), COALESCE()
Slide: 32
MySQL for Oracle Developers
SELECT
SELECT/FROM/WHERE/GROUP BY/HAVING
LIMIT n[,m]
LIKE
REGEXPhttp://dev.mysql.com/doc/refman/5.0/en/select.html
UNION, UNION ALLhttp://dev.mysql.com/doc/refman/5.0/en/union.html
ROWNUM
ROWID
UNION, UNION ALLINTERSECT, MINUS
Slide: 33
MySQL for Oracle Developers
JOIN
INNER JOINOUTER JOINNO FULL OUTER JOIN
http://dev.mysql.com/doc/refman/5.0/en/join.html
ON, NATURAL, USINGPARTITION BY
join_table: table_reference [INNER | CROSS] JOIN table_factor [join_condition] table_reference STRAIGHT_JOIN table_factor table_reference STRAIGHT_JOIN table_factor ON condition table_reference LEFT [OUTER] JOIN table_reference join_condition table_reference NATURAL [LEFT [OUTER]] JOIN table_factor table_reference RIGHT [OUTER] JOIN table_reference join_condition table_reference NATURAL [RIGHT [OUTER]] JOIN table_factor
Slide: 34
MySQL for Oracle Developers
Sub Queries
IN, NOT IN
ALL, ANY, SOME
EXISTS, NOT EXISTS
Correlated subqueries
In FROM Clause
http://dev.mysql.com/doc/refman/5.0/en/subqueries.html
WITH
Slide: 35
MySQL for Oracle Developers
Full Text Search
FULLTEXT Index
MyISAM Storage Engine Only e.g. FULLTEXT KEY indx_title_description(title,description)
SELECT f.film_id, f.title, f.description FROM film_text fWHERE MATCH (title,description) AGAINST ('MySQL');SELECT f.film_id, f.title, f.description FROM film_text f WHERE MATCH (title,description)AGAINST ('+MySQL Monkey' IN BOOLEAN MODE);SELECT f.film_id, f.title, f.description FROM film_text f WHERE MATCH (title,description)AGAINST ('database' WITH QUERY EXPANSION);
http://dev.mysql.com/doc/refman/5.0/en/fulltextsearch.html
ORACLE TEXT
Slide: 36
MySQL for Oracle Developers
INSERT
INSERT INTO [table] SET [col]=[value], ...
Multiple Row Insert
DEFAULT valuesDEFAULT or DEFAULT(col_name)
AUTO_INCREMENT NULL,0 or col not stated http://dev.mysql.com/doc/refman/5.0/en/insert.html
INSERT ALL ... WHEN
Slide: 37
MySQL for Oracle Developers
UPDATE
ORDER BY/LIMITe.g. UPDATE CacheTable SET expiry = NOW() ORDER BY oldest LIMIT 10
Multiple Table UpdateUPDATE items,month SET items.price=month.price WHERE items.id=month.id;
http://dev.mysql.com/doc/refman/5.0/en/update.html
Slide: 38
MySQL for Oracle Developers
DELETE
ORDER BY/LIMITe.g. DELETE FROM CacheTable ORDER BY oldest LIMIT 10;
Multiple Table DeleteDELETE t1, t2 FROM t1, t2, t3 WHERE t1.id=t2.id AND t2.id=t3.id;DELETE FROM t1, t2 USING t1, t2, t3 WHERE t1.id=t2.id AND t2.id=t3.id;
http://dev.mysql.com/doc/refman/5.0/en/delete.html
Slide: 39
MySQL for Oracle Developers
REPLACE
Combined Insert/UpdateREPLACE works exactly like INSERT, except that if an old record in the table has the same value as a new record on a unique index, the old record is deleted before the new record is inserted.
Affects Trigger Operationhttp://dev.mysql.com/doc/refman/5.0/en/replace.html
MERGE (very cumbersome)
Slide: 40
MySQL for Oracle Developers
DML Syntax Differences
LOW_PRIORITY execution of the INSERT is delayed until no other clients are
reading from the table. Not good on readheavy environment
INSERT, UPDATE, DELETE, REPLACEINSERT LOW_PRIORITY INTO LogTable VALUES (); Bad Idea
INFO
Slide: 41
MySQL for Oracle Developers
DML Syntax Differences
HIGH_PRIORITY gives the SELECT higher priority than a statement that updatesOnly for queries that are very fast and must be done at once
SELECT, INSERTSELECT HIGH_PRIORITY FROM CacheTable;
INFO
Slide: 42
MySQL for Oracle Developers
DML Syntax Differences
DELAYED the server puts the row or rows to be inserted into a buffer, and the client issuing the INSERT DELAYED statement can then continue immediately.
INSERT, REPLACE StatementsINSERT DELAYED INTO LogTable VALUES ();
http://dev.mysql.com/doc/refman/5.0/en/insertdelayed.html
Good IdeaNon Critical Data
INFO
Slide: 43
MySQL for Oracle Developers
DML Syntax Differences
IGNOREerrors that occur while executing the INSERT statement are treated as warnings instead
INSERT, UPDATE, DELETE StatementsINSERT IGNORE INTO LogTable VALUES ();
Poor Programming
Practice
INFO
Slide: 44
MySQL for Oracle Developers
Data Types
NumericTINYINT,SMALLINT,MEDIUMINT,INT,BIGINTFLOAT,DOUBLE,DECIMAL,BIT
DateDATE,TIME,DATETIME,TIMESTAMP,YEAR
http://dev.mysql.com/doc/refman/5.0/en/datatypes.html
http://dev.mysql.com/doc/refman/5.0/en/storagerequirements.html
Slide: 45
MySQL for Oracle Developers
Data Types
StringCHAR,VARCHAR,BINARY,VARBINARY,TINYTEXT,MEDIUMTEXT,TEXT,LONGTEXTTINYBLOB,MEDIUMBLOB,BLOG,LONGBLOBENUM,SET
http://dev.mysql.com/doc/refman/5.0/en/datatypes.html
http://dev.mysql.com/doc/refman/5.0/en/storagerequirements.html
Slide: 46
MySQL for Oracle Developers
Data Types
SpatialGEOMETRY, POINT, LINESTRING, POLYGON,GEOMETRYCOLLECTION, MULTILINESTRING,MULTIPOINT, MULTIPOLYGON
http://dev.mysql.com/doc/refman/5.0/en/spatialextensions.html
Slide: 47
MySQL for Oracle Developers
Numeric Data Types
FLOAT, DOUBLE – floating point typese.g. lat FLOAT(10,6), lon FLOAT(10,6)
DECIMAL – fixed point typee.g. amt DECIMAL(10,2) NOT NULL,
INT Integer
UNSIGNED, ZEROFILLe.g cnt INT(6) UNSIGNED ZEROFILL,
Floating Point NUMBERFixed Point NUMBER(p,s)Integer NUMBER(p)
Slide: 48
MySQL for Oracle Developers
Date Data Types
TIMESTAMPFirst TIMESTAMP column defaults to last update date/time
Good for behind the scenes auditing
Second only granularity
CREATE TABLE ... last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, ...
TIMESTAMP (faction precision)WITH [LOCAL] TIMEZONE
Slide: 49
MySQL for Oracle Developers
Constraint Data Types
ENUMsize ENUM('S','M','L','XL','XXL')
http://dev.mysql.com/doc/refman/5.0/en/enum.html
SETcolor SET ('Red','Blue','Green','White','Black')
http://dev.mysql.com/doc/refman/5.0/en/set.html
http://dev.mysql.com/doc/refman/5.0/en/constraintenum.html
Slide: 50
MySQL for Oracle Developers
Large Objects (LOB)
TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB
TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT
255 bytes, 64K, 16M, 4G
http://dev.mysql.com/doc/refman/5.0/en/blob.html
CLOB, BLOB,NCLOB, BFILE
Slide: 51
MySQL for Oracle Developers
String Functions
SELECT CONCAT('A','B');
SELECT CONCAT_WS(',','a','b','c',d');
SET sql_mode='PIPES_AS_CONCAT';SELECT 'A'||'B';
http://dev.mysql.com/doc/refman/5.0/en/stringfunctions.html
'A' || 'B'CONCAT('A','B')
Slide: 52
MySQL for Oracle Developers
String Functions
Multiple Character Set SupportSHOW CHARACTER SET;SELECT 'Test' = 'TEST';SELECT _latin1 'Test' = 'TEST';SELECT _latin1 'Test' = BINARY 'TEST';
CollationDefines String ComparisionsDefines Sorting Order
http://dev.mysql.com/doc/refman/5.0/en/charset.html
Slide: 53
MySQL for Oracle Developers
Date Calendar
Proleptic Gregorian calendar
October 415 1582 cutoverPre JulianPost Gregorian
The “YearZero” ruleThe “LeapYear Calculation” rule
http://dev.mysql.com/doc/refman/5.0/en/mysqlcalendar.html
Julian Dates?http://www.orafaq.com/papers/dates_o.doc
INFO
Slide: 54
MySQL for Oracle Developers
Date Functions
SELECT CURDATE(), NOW(), SYSDATE()Second only granularity
http://dev.mysql.com/doc/refman/5.0/en/dateandtimefunctions.html
TimeZones UTC or namede.g. SET time_zone = '+10:00'; 'Europe/Helsinki', 'US/Eastern', 'MET', 'SYSTEM'Manual Installation step to seed data
http://dev.mysql.com/doc/refman/5.0/en/timezonesupport.html
Slide: 55
MySQL for Oracle Developers
Control Flow Functions
IFSELECT IF(1>0,'yes','no');
> 'yes'
CASESELECT CASE WHEN 1>0 THEN 'yes' ELSE 'no' END;
> 'true'SELECT CASE 'B' WHEN 'a' THEN 1 WHEN 'b' THEN 2 END;
> 2SELECT CASE BINARY 'B' WHEN 'a' THEN 1 WHEN 'b' THEN 2 END;
> NULL
http://dev.mysql.com/doc/refman/5.0/en/controlflowfunctions.html
DECODE() CASE()
Slide: 56
MySQL for Oracle Developers
System Variables
Server (e.g. /etc/my.cnf)sort_buffer_size=500000
GLOBAL SET GLOBAL sort_buffer_size=750000;
SESSION SET SESSION sort_buffer_size=1000000;SELECT @@global.sort_buffer_size, @@session.sort_buffer_size;
INFO
Slide: 57
MySQL for Oracle Developers
SHOW
SHOW TABLES;
SHOW WARNINGS;
SHOW STATUS; FLUSH STATUS;
SHOW VARIABLES;
SHOW VARIABLES LIKE '%size%';
SHOW VARIABLES LIKE 'sort_buffer_size';
SHOW GLOBAL VARIABLES LIKE 'sort_buffer_size';
Slide: 58
MySQL for Oracle Developers
SQL Mode
Key ModesANSI STRICT_TRANS_TABLES TRADITIONAL
SHOW VARIABLES LIKE 'sql_mode';
SET sql_mode='strict_all_tables';
Slide: 59
MySQL for Oracle Developers
SQL Mode
Oracle CompatibilitySET sql_mode='PIPES_AS_CONCAT,ANSI_QUOTES, IGNORE_SPACE,NO_KEY_OPTIONS,NO_TABLE_OPTIONS, NO_FIELD_OPTIONS, NO_AUTO_CREATE_USER';
http://dev.mysql.com/doc/refman/5.0/en/serversqlmode.html
http://dev.mysql.com/techresources/articles/mysqldataintegrity.html
Slide: 60
MySQL for Oracle Developers
Procedural Language Support
Stored Procedures
Functions
UDF User Defined Functions
Triggers
Slide: 61
MySQL for Oracle Developers
Procedures
No Package Capabilites
http://bugs.mysql.com/bug.php?id=11696NO RAISE Error CapabilityNo Named ParametersNo Overloading
http://dev.mysql.com/doc/refman/5.0/en/storedprocedures.html
General Purpose Stored Routines Library http://www.nongnu.org/mysqlsrlib/
OS
Slide: 62
MySQL for Oracle Developers
ProceduresDELIMITER //CREATE PROCEDURE rewards_report ( IN min_monthly_purchases TINYINT UNSIGNED , IN min_dollar_amount_purchased DECIMAL(10,2) UNSIGNED , OUT count_rewardees INT)LANGUAGE SQLNOT DETERMINISTICREADS SQL DATASQL SECURITY DEFINERCOMMENT 'Provides a customizable report on best customers'proc: BEGIN
DECLARE last_month_start DATE; DECLARE last_month_end DATE;
/* Some sanity checks... */ IF min_monthly_purchases = 0 THEN SELECT 'Minimum monthly purchases parameter must be > 0'; LEAVE proc; END IF; SET last_month_start = DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH); CREATE TEMPORARY TABLE tmpCustomer (customer_id SMALLINT UNSIGNED NOT NULL PRIMARY KEY); ... SELECT COUNT(*) FROM tmpCustomer INTO count_rewardees; DROP TABLE tmpCustomer;END //
INFO
Slide: 63
MySQL for Oracle Developers
Functions
Example – Wrap IFNULL with NVL for Oracle Compatibility
DELIMITER //CREATE FUNCTION NVL(IN col VARCHAR(100), IN nullvalue VARCHAR(100)) RETURNS VARCHAR(100)BEGIN RETURN IFNULL(col,nullvalue);END;//DELIMITER ;
SELECT NVL(col,'Unknown') FROM table
Slide: 64
MySQL for Oracle Developers
Functions
SHOW CREATE FUNCTION 'NVL';
SHOW FUNCTION STATUS LIKE 'NVL';
SELECT routine_name, routine_schema, routine_type FROM INFORMATION_SHEMA.routines;
Slide: 65
MySQL for Oracle Developers
User Defined Functions (UDF)
Added as Object Files
http://dev.mysql.com/doc/refman/5.0/en/addingfunctions.html
$ gcc I /usr/include/mysql/ shared o syslogudf.so syslogudf.c$ cp syslogudf.so /usr/libmysql> create function logger returns integer soname 'syslogudf.so';mysql> select logger('logging from ' + version());$ tail /var/log/messages
INFO
Slide: 66
MySQL for Oracle Developers
User Defined Functions (UDF)#include <mysql.h>#include <string.h>#include <syslog.h>
my_bool logger_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { initid>maybe_null=0; return 0;}
long long logger(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error) { if (args>arg_count != 1) { strcpy(error, "LOGGER(): needs message"); return 1; } if (args>arg_type[0] != STRING_RESULT) { strcpy(error, "LOGGER() message should be string"); return 1; }
syslog(LOG_INFO,"%s",args>args[0]); *is_null = 0; *error = 0; return 0;} http://dammit.lt/stream/mysql/
INFO
Slide: 67
MySQL for Oracle Developers
User Defined Functions (UDF)
MySQL Message API
Utilises Spread Toolkit www.spread.org
http://forge.mysql.com/projects/view.php?id=2
MySQL Message API
INFO
Slide: 68
MySQL for Oracle Developers
Triggers
[BEFORE|AFTER] [INSERT|UPDATE|DELETE]
Only one trigger per table per DML statement
MissingINSTEAD OF (used in Views)No OR DML (e.g. INSERT OR UPDATE)No OR REPLACE (e.g. CREATE OR REPLACENo WHEN ConditionOnly for DML statements (e.g. No DROP)
http://dev.mysql.com/doc/refman/5.0/en/triggers.html
Slide: 69
MySQL for Oracle Developers
TriggersDELIMITER ;;CREATE TRIGGER `ins_film` AFTER INSERT ON `film` FOR EACH ROW BEGIN INSERT INTO film_text (film_id, title, description) VALUES (new.film_id, new.title, new.description); END;;
CREATE TRIGGER `upd_film` AFTER UPDATE ON `film` FOR EACH ROW BEGIN IF (old.title != new.title) or (old.description != new.description) THEN UPDATE film_text SET title=new.title, description=new.description, film_id=new.film_id WHERE film_id=old.film_id; END IF; END;;
CREATE TRIGGER `del_film` AFTER DELETE ON `film` FOR EACH ROW BEGIN DELETE FROM film_text WHERE film_id = old.film_id;END;;DELIMITER ;
INFO
Slide: 70
MySQL for Oracle Developers
Query Performance Analysis
EXPLAIN [EXTENDED] SELECT select_options
SELECT only
[SELECT] PROCEDURE ANALYSE();
http://dev.mysql.com/doc/refman/5.0/en/explain.html
EXPLAIN PLAN FOR [statement]PLAN_TABLE
INFO
Slide: 71
MySQL for Oracle Developers
Query Performance Analysis
The Slow Query Log
long_query_time=5 (my.cnf)
mysqld logslowqueries=[filename]
logqueriesnotusingindexes
logslowadminstatements
http://dev.mysql.com/doc/refman/5.0/en/slowquerylog.html
INFO
Slide: 72
MySQL for Oracle Developers
MySQL Commands
mysqlmysqldmysqladminmysqlmanagermysqlcheckmysqldumpmysqlimportmysqlcheck
myisamchkmyisamlogmyisampackmysqlbinlogperrormysqlupgrademysqlslap
http://dev.mysql.com/doc/refman/5.0/en/clientutilityprograms.html
5.1
INFO
Slide: 73
MySQL for Oracle Developers
INFORMATION_SCHEMA
Smaller set of tablesTABLES, COLUMNS, VIEWS, ROUTINES, USER_PREVILEGES
PROCESSLIST http://dev.mysql.com/doc/refman/5.0/en/informationschema.html
http://www.xcdsql.org/MySQL/information_schema/5.1/MySQL_5_1_INFORMATION_SCHEMA.html
Oracle Data Dictionary
Dynamic Performance Views (V$)
5.1
Slide: 74
MySQL for Oracle Developers
Slide: 75
MySQL for Oracle Developers
INFORMATION_SCHEMA
ExamplesSELECT TABLE_SCHEMA, SUM((DATA_LENGTH + INDEX_LENGTH) / (1024 * 1024)) AS SIZE_MB FROM INFORMATION_SCHEMA.TABLESGROUP 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 = 'test';
INFO
Slide: 76
MySQL for Oracle Developers
INFORMATION_SCHEMA
ExamplesSELECT 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_tablesFROM information_schema.schemata sLEFT JOIN information_schema.tables t ON s.schema_name = t.table_schemaWHERE s.schema_name != 'information_schema'GROUP BY s.schema_name ORDER BY pct_used DESC\G
INFO
Slide: 77
MySQL for Oracle Developers
Helpful SQL Additions
LOAD DATA INFILE
SELECT INTO OUTFILE
DROP [object] IF EXISTS [name] DROP TABLE IF EXISTS TableName;
Slide: 78
MySQL for Oracle Developers
MySQL 5.1 Major Features
Partitioning
Log Tables
Row Based Replication
Events
Federated Tables
Cluster Replication
5.1
Slide: 79
MySQL for Oracle Developers
End User Tools
MySQL Query BrowserMySQL AdministratorMySQL Workbench3rd Party Products
Slide: 80
MySQL for Oracle Developers
MySQL Query Browser
Query ToolbarEasily Create, Edit, and Debug SQL Statements
Script EditorObject BrowserDatabase ExplorerTable Editor
Visually Create and Modify Tableshttp://www.mysql.com/products/tools/querybrowser/
SQL Developer / TOAD
Slide: 81
MySQL for Oracle Developers
MySQL Administrator
User AdministrationSingle View Dynamic Health MonitoringQuickly Optimize MySQLRapid Disaster Prevention and RecoveryServer Information AtaGlanceView Replication StatusView Server Logs
http://www.mysql.com/products/tools/administrator/
OEM, APEX
Slide: 82
MySQL for Oracle Developers
MySQL Workbench
Reverse Engineer DatabaseDatabase/Model synchronizationConcept/Logical/Physical DesignsDBDesigner4 import/export modelExtending
Figure StylesheetsScriptsPlugins
Oracle Designer
http://forge.mysql.com/wiki/index.php/MySQL_Workbench
Slide: 83
MySQL for Oracle Developers
3 rd Party Tools
PhpMyAdminhttp://www.phpmyadmin.net
Toad for MySQLhttp://www.toadsoft.com/toadmysql/
Slide: 84
MySQL for Oracle Developers
Other MySQL Products
MySQL ConnectorsODBC, JDBC, ADO.NET, MPX
MySQL Migration Toolkit
MySQL Network – Commercial Support
Eventum
INFO
Slide: 85
MySQL for Oracle Developers
What's Missing
Object Structure
Table Snapshots
Materialized Views
Check Constraints
CREATE VIEW ... WITH CHECK OPTION;
Flashback queries
Synonyms
CREATE TYPE [obj] AS OBJECT
Slide: 86
MySQL for Oracle Developers
What's Missing
SQL reports
No Memory Pinning capabilities
No wrapping capability (protect source)
No Java procedural language support
COLUMN name FORMAT a40 SET LINESIZE 100 SPOOL [file]
Slide: 87
MySQL for Oracle Developers
What we covered?
SQLSQL*PlusPL/SQLTools Suite
Open Source OpportunityDocumentation References
Slide: 88
MySQL for Oracle Developers
For access to this paper, more detailed notes and other information, please visit.
http://www.arabx.com.au
Slide: 89
MySQL for Oracle Developers
Referenceshttp://www.mysql.com MySQL Web Site
http://dev.mysql.com MySQL Developer Zone
http://forums.mysql.com MySQL Forums
http://www.mysql.com/training/certification/ MySQL Certification
http://www.planetmysql.org MySQL Blogs
www.mysqldevelopment.com MySQL resources/tutorials
INFO
Slide: 90
MySQL for Oracle Developers
ReferencesStorage Engines
http://dev.mysql.com/techresources/articles/mysql_5.0_psea1.html
http://dev.mysql.com/techresources/articles/mysql_5.0_psea2.html
http://dev.mysql.com/techresources/articles/creatingnewstorageengine.html
http://www.mysql.com/whymysql/whitepapers/mysql_wp_pluggable.php
Stored Procedures
http://www.nongnu.org/mysqlsrlib/ General Purpose Stored Routines Library
http://dev.mysql.com/techresources/articles/mysqlstoredprocedures.html
INFO
Slide: 91
MySQL for Oracle Developers
References
Recommended ReadingMySQL by Paul DuBois
INFO