Mysql For Oracle Dbas and Developers
Mysql For Oracle Dbas and Developers
MYSQL_HOME=/home/oracle/products/mysql-version
Outline
My Background
DBA
Terminology
MySQL Installation
MySQL Configuration
GOTCHA
Multiple MySQL Instances
my.cnf
- Watch out for /etc/my.cnf, /etc/mysql/my.cnf
- Best Practice $MYSQL_HOME/my.cnf
- --defaults-file=<file>
http://dev.mysql.com/doc/refman/5.1/en/option-files.html
MySQL Directories
my.cnf options
basedir ($MYSQL_HOME)
- e.g. /opt/mysql-5.1.16-beta-linux-i686-glib23
datadir (defaults to $MYSQL_HOME/data)
tmpdir (important as mysql behaves unpredictability if full)
innodb_[...]_home_dir
http://dev.mysql.com/doc/refman/5.1/en/log-tables.html
http://dev.mysql.com/doc/refman/5.1/en/information-schema.html
http://www.xcdsql.org/MySQL/information_schema/5.1/MySQL_5_1_INFORMATION_SCHEMA.html
SQL Examples
SQL Examples
SHOW Commands
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';
Backup
Missing Functionality
Commercial strength – unbreakable (Planned 6.0)
Storage Engine Driven
Innodb
Also PBXT, Falcon
- Hot Backup
- mysqldump --single-transaction --master-data
- InnoDB Hot Backup
Backup
MyISAM Only
- Cold Backup via File Copy
- LVM Snapshot
SE Mixture
- Use Replication Slave
Online Backup/Recovery
MySQL 6.0 Demo
Backup ALL…
Tools
Missing Functionality
- Enterprise Level Monitoring
SHOW PROFILE (5.0.38 - Community)
Microsecond Patch (5.0.33 - Slow query granularity)
mytop/innotop/ndbtop
MySQL Toolkit http://sourceforge.net/projects/mysqltoolkit
phpMyAdmin
Ronald Bradford, MySQL Inc
MySQL Conference & Expo 2007 Page: 23
MySQL for Oracle Dudes
SHOW PROFILE
mysql> show profile SOURCE,MEMORY for query 4;
+--------------------+------------+-----------------------+---------------+-------------+
| Status | Duration | Source_function | Source_file | Source_line |
+--------------------+------------+-----------------------+---------------+-------------+
| Opening tables | 0.00013200 | open_tables | sql_base.cc | 2106 |
| System lock | 0.00001800 | mysql_lock_tables | lock.cc | 153 |
| Table lock | 0.00000600 | mysql_lock_tables | lock.cc | 162 |
| init | 0.00001300 | mysql_select | sql_select.cc | 2073 |
| optimizing | 0.00004800 | optimize | sql_select.cc | 617 |
| statistics | 0.00002500 | optimize | sql_select.cc | 773 |
| preparing | 0.00005200 | optimize | sql_select.cc | 783 |
| executing | 0.00002200 | exec | sql_select.cc | 1407 |
| Sending data | 0.00000500 | exec | sql_select.cc | 1925 |
| end | 0.00786600 | mysql_select | sql_select.cc | 2118 |
| query end | 0.00001400 | mysql_execute_command | sql_parse.cc | 5085 |
| freeing items | 0.00000700 | mysql_parse | sql_parse.cc | 5973 |
| closing tables | 0.00001900 | dispatch_command | sql_parse.cc | 2120 |
| logging slow query | 0.00001000 | log_slow_statement | sql_parse.cc | 2178 |
| cleaning up | 0.00000500 | dispatch_command | sql_parse.cc | 2143 |
+--------------------+------------+-----------------------+---------------+-------------+
15 rows in set (0.01 sec)
GUI Tools
MySQL Administrator
Quest Spotlight
Toad
MySQL
Enterprise
Tools
TIP
mysqladmin -r -i 1 extended-status
- Gives change in status variables per second
- Lacks timestamp
Monitor specifics
- Com_*
- Innodb_*, Innodb_buffer_pool_*
- Connections
- Created_tmp_*
Ronald Bradford, MySQL Inc
MySQL Conference & Expo 2007 Page: 26
MySQL for Oracle Dudes
Tools
Example
Idle
- $ mysqladmin -r -i 1 extended-status | grep -v “ | 0 “
+-----------------------------------+------------+
| Variable_name | Value |
+-----------------------------------+------------+
| Bytes_received | 35 |
| Bytes_sent | 6155 |
| Com_show_status | 1 |
| Created_tmp_tables | 1 |
| Handler_read_rnd_next | 246 |
| Handler_write | 245 |
| Questions | 1 |
| Select_scan | 1 |
| Uptime | 1 |
+-----------------------------------+------------+
Tools
Under load
- $ mysqladmin -r -i 1 extended-status | grep -v “ | 0 “
+-----------------------------------+------------+ Erroneous Commands
| Variable_name | Value | Causing Round Trips
+-----------------------------------+------------+
| Bytes_received | 1020909 |
| Bytes_sent | 195358 | Buried in JDBC Usage
| Com_insert | 274 | PreparedStatement
| Com_select | 132 |
| Com_set_option | 264 | .setMaxRows()
| Handler_read_key | 505 |
| Handler_update | 252 |
| Handler_write | 519 |
| Questions | 1356 |
| Table_locks_immediate | 536 |
| Table_locks_waited | 2 |
+-----------------------------------+------------+
Ronald Bradford, MySQL Inc
MySQL Conference & Expo 2007 Page: 28
MySQL for Oracle Dudes
Default Installation
AUTO COMMIT
GOTCHA
By Default enabled in MySQL
- Ops I deleted the wrong data, I'll just ROLLBACK
- Non Transactional Storage Engines
- SET AUTOCOMMIT = {0 | 1};
SQL*Plus Reporting
No Alternative
Nice Feature- Vertical Output Display
- SELECT columns FROM table \G
Query Cache
Contrasting Buffers
Area MySQL Oracle Microsoft SQL Server
Memory Caches • MyISAM key caches • Data cache (variants) • Buffer cache
• InnoDB data cache • Log buffer • SQL cache
• InnoDB log cache • Shared Pool • Misc caches (lock,
• Dictionary cache • Java Pool connection, workspace, etc.)
• Falcon caches • Large Pool
• Query Cache • PGA
• User caches
Redo/Undo Logs • InnoDB Undo Space • Undo Tablespace (9i+) • TempDB (2005+)
• InnoDB Logs • Redo Logs • Transaction Logs
• Falcon Log • Archive Logs
• Binary Log
DEVELOPER
Sequences Replacement
AUTO_INCREMENT
e.g. id INT NOT NULL AUTO_INCREMENT,
- Must be tied to a [table].[column]
- Only one per table
- No system wide capability
- LAST_INSERT_ID()
- No get next capability
Data Comparison
DDL Syntax
Escaped Reserved Words are allowed
e.g. CREATE TABLE `group` (...);
e.g. CREATE TABLE “insert” (...); * sql_mode
Tables/Columns/Triggers/Stored Procedures
Space and other special characters allowed
Operating System Dependent
e.g. CREATE TABLE `My Table Name` (...);
Stored Procedures
Earlier Session
“Using Stored Routines for MySQL Administration”
Stored Procedures
http://forge.mysql.com/projects/view.php?id=35
Locking
SQL_MODE
SET SQL_MODE=TRADITIONAL,ORACLE
http://dev.mysql.com/doc/refman/5.1/en/server-sql-mode.html
SQL_MODE
String Concatenation
- SELECT CONCAT('A','B');
- SELECT CONCAT_WS(',','a','b','c',d');
Emulate Oracle Behaviour
SET sql_mode='PIPES_AS_CONCAT';
- SELECT 'A'||'B'; May break
other tools
TIMESTAMP
TIP
Remove DB level auditing via triggers
- last_modified TIMESTAMP ON UPDATE CREATE_TIMESTAMP,
Multi-record INSERT
REPLACE
LOW_PRORITY | HIGH PRIORITY
INSERT DELAYED
MIGRATION
Migration
MYSQL = (DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))
(CONNECT_DATA=(SID=MYSQL)) (HS=OK))
Oracle Migration
Oracle Migration
http://www.mysql.com/products/tools/migration-toolkit/
Numeric Precision/Rounding
Character Sets (multi-byte data)
CHAR usage
- CHAR(5)
- Oracle 'abc ' - 5 characters long
- MySQL 'abc' - 3 characters long
No Packages
Restricted Triggers
- Only one trigger per table per DML statement
- Missing
- INSTEAD,
- INSERT OR UPDATE
- OR REPLACE
- Only for DML Statements
Ronald Bradford, MySQL Inc
MySQL Conference & Expo 2007 Page: 57
MySQL for Oracle Dudes
Date Functions
- CURDATE(), NOW()
Data Formats
- Default is YYYY-MM-DD
Case insensitive searching
- no UPPER(column) = UPPER(value)
- Character Set/Collation specific
CLOSING
Pronunciation
References
Recommended Reading
Support Me
Buy a T-shirt !
Q&A