SlideShare une entreprise Scribd logo
1  sur  85
Télécharger pour lire hors ligne
<Insert Picture Here>
MySQL: Crash Course
Keith Larson
keith.larson@oracle.com
MySQL Community Manager
http://sqlhjalp.com/pdf/MySQL_crashcourse_2012.pdf
The following is intended to outline our general product
direction. It is intended for information purposes only,
and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or
functionality, and should not be relied upon in making
purchasing decisions.
The development, release, and timing of any features or
functionality described for Oracle’s products remains at
the sole discretion of Oracle.
Safe Harbor Statement
Who am I and who are you?
Keith Larson
keith.larson@oracle.com
MySQL Community Manager
http://www.sqlhjalp.com/
Started with MySQL during the dot.com days.
Primary real world work was with a MySQL InnoDB replicated chain environment that
easily held over 4 billion rows of user data.
Numerous other sites developed on LAMP stack over the last 13 years.
Who are you?
DBAs?
Developers?
Copyright Oracle Corporation 2012 3
• Oracle's Investment into MySQL
• A high-level overview
• Familiarize with the key concepts
• MySQL Editions
Session Agenda
Copyright Oracle Corporation 2012 4
Copyright Oracle Corporation 2012 5
The official way to pronounce “MySQL” is
“My Ess Que Ell”
but we do not mind if you pronounce it as
“my sequel”
It was named after Monty's Daughter Maria.
Pronunciation
Copyright Oracle Corporation 2012 6
Sakila is the official name of the MySQL dolphin (the logo).
The name comes from a competition to
name
the dolphin. The winning name was
submitted by
Ambrose Twebaze, an Open Source
software
developer from Swaziland, Africa.
According to Ambrose, the name Sakila
has its roots in SiSwati, the local language
of Swaziland.
Sakila is also the name of a town in
Arusha,Tanzania, near Ambrose's country
of origin, Uganda.
What do you think of when you think of a dolphin?

Fast

Love-able

Agile

Intelligent

Social

Everyone loves a dolphin
What is Sakila?
https://wikis.oracle.com/pages/viewpage.action?pageId=27394602
Copyright Oracle Corporation 2012 7
MySQL AB founded 1995 by Michael Widenius, David Axmark, and
Allan Larsson
Initial release : 23 May 1995
Marten Mickos was CEO January 2001 to February 2008
2005 - Oracle Acquires Innobase (founded by Heikki Tuuri)
A little background
Copyright Oracle Corporation 2012 8
Acquired by SUN Microsystems in 2008 for 1B USD
Acquired by Oracle in 2009
Dual licensing: GPL v.2 + commercial
Easy of use: the 15 minute rule has been cut down to 3 mins on
windows
“M” in “LAMP” stack
A little background
http://www.mysql.com/news-and-events/sun-to-acquire-mysql.html
Marten Mickos CEO MySQL AB Jonathan Schwartz CEO SUN Larry Ellison CEO Oracle
Copyright Oracle Corporation 2012 9
• Oracle's Investment into MySQL
Session Agenda
Copyright Oracle Corporation 2012 10
>70% of Oracle Shops run MySQL
Copyright Oracle Corporation 2012 11

Fast

Agile

Ease of use

Scalable

Enterprise Ready
Q2 CY2010 Q3 CY2010 Q4 CY2010 Q1 CY2011
• MySQL Workbench 5.2
GA!
• MySQL Database 5.5
• MySQL Enterprise Backup 3.5
• MySQL Enterprise Monitor 2.3
• MySQL Cluster Manager 1.1
All GA!
A Better MySQL
Q2 CY2011
•MySQL Enterprise Monitor 2.2
•MySQL Cluster 7.1
• MySQL Cluster Manager 1.0
All GA!
• MySQL Database
5.6
• MySQL Cluster 7.2
DMR*
and MySQL Labs!
(“early and often”)
*Development Milestone Release
Continuous Innovation with more product
releases than ever before
Copyright Oracle Corporation 2012 12
MySQL On the Cover
http://www.oracle.com/technetwork/issue-archive/2011/11-jan/index-191276.html
Copyright Oracle Corporation 2012 13
Enterprise 2.0SaaS, Cloud
Web OEM / ISV’s
Telecommunications
Rely on MySQL
Industry Leading Customers
Copyright Oracle Corporation 2012 14
• A high-level overview
Session Agenda
Copyright Oracle Corporation 2012 15
MySQL Terminology
• Database ( Files )
• Database Instance ( memory)memory
• Schema
• User
• Table Space
• Database Server Instance
• Database Server Instance
• Database
• User
• Table Space
• Storage Engine
Copyright Oracle Corporation 2012 16
Error Log
– log-error
Binary Log
– Log-bin custom set via my.cnf
Slow Query Log
– Log-slow-queries
– Slow-query-time
– log-queries-not-using-indexes
General Log
– Log
http://dev.mysql.com/doc/refman/5.5/en/server-logs.html
MySQL Logs
Copyright Oracle Corporation 2012 17
SHOW VARIABLES like '%log%';
+-----------------------------------------+-------------------------------------+
| Variable_name | Value |
+-----------------------------------------+-------------------------------------+
| back_log | 50 |
| binlog_cache_size | 32768 |
| binlog_checksum | NONE |
| binlog_direct_non_transactional_updates | OFF |
| binlog_format | MIXED |
| binlog_row_image | FULL |
| binlog_rows_query_log_events | OFF |
| binlog_stmt_cache_size | 32768 |
| expire_logs_days | 0 |
| general_log | OFF |
| general_log_file | /var/lib/mysql/kdlarson-pc.log |
…...
Copyright Oracle Corporation 2012 18
MySQL Logs
• Centralized monitoring of queries
without Slow Query Log, SHOW
PROCESSLIST;
• Enabled via MySQL Connectors
• Aggregated view of query execution
counts, time, and rows
• Visual “grab and go” correlation with
Monitor graphs
• Traces query executions back to
source code
Saves you time parsing atomic
executions from logs. Finds
problems you cannot find yourself.
MySQL Query Analyzer
Copyright Oracle Corporation 2012 19
http://carlos.syr.edu/oracle-database-architecture/
Oracle Database Architecture
Copyright Oracle Corporation 2012 20
MySQL Database Architecture
Copyright Oracle Corporation 2012 21
Standalone (mysqld)
UNIX daemon
Windows service
Regular process on UNIX or Windows
Embedded (libmysqld)
Shared / Dynamic library
MySQL Server
Copyright Oracle Corporation 2012 22
InnoDB
DB1
InnoDB
DB2
MyISAM
DB3
InnoDB MyISAM
Core
SQL-query processing, …
Plugin 1 Plugin 2 Plugin 3
The Core
Plugins
Storage Engines
Full-text search
plugins
Audit plugins
Authentication
plugins
…
MySQL Server Components
Copyright Oracle Corporation 2012 23
The Storage Engine (SE) defines data
storage and retrieval
Every regular table belongs to some SE
Most notable Storage Engines:
InnoDB (default since 5.5)
– fully transactional SE
MyISAM (default prior to 5.5)
– NON-transactional SE
Default Storage Engine used it not
defined
MySQL Storage Engines
CREATE TABLE `City` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Name` char(35) NOT NULL DEFAULT '',
`CountryCode` char(3) NOT NULL DEFAULT '',
`District` char(20) NOT NULL DEFAULT '',
`Population` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`),
KEY `CountryCode` (`CountryCode`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
Copyright Oracle Corporation 2012 24
Select a specialized storage engine for a particular application
need.
InnoDB: a high-reliability and high-performance storage engine
for MySQL designed for transaction processing. It follows the
ACID model. Row-level locking and Oracle-style consistent
reads increase multi-user concurrency and performance
MyISAM: -oldest storage engine has many features
that have been developed over years.
Memory: creates tables with contents that are stored in memory.
MySQL Cluster offers the same features as the MEMORY
engine with higher performance levels, and provides
additional features
MySQL Storage Engines
Copyright Oracle Corporation 2012 25
CSV: data file is a plain text file
ARCHIVE: is used for storing large amounts of data without
indexes in a very small footprint.
BLACKHOLE:accepts data but throws
it away and does not store it but the
binary log is enabled.
MySQL Storage Engines
Copyright Oracle Corporation 2012 26
Open Source
Limitations Relating to Storage Engines
Horizontal partitioning
(distribute rows, not columns)
Partitioning functions:
The modulus
Range
Internal hashing function
Linear hashing function
MySQL Partitioning
http://dev.mysql.com/doc/refman/5.1/en/partitioning-overview.html
http://dev.mysql.com/tech-resources/articles/mysql_55_partitioning.html
Copyright Oracle Corporation 2012 27
CREATE TABLE members (
firstname VARCHAR(25) NOT NULL,
lastname VARCHAR(25) NOT NULL,
username VARCHAR(16) NOT NULL,
email VARCHAR(35),
joined DATE NOT NULL
)
PARTITION BY RANGE( YEAR(joined) ) (
PARTITION p0 VALUES LESS THAN (1960),
PARTITION p1 VALUES LESS THAN (1970),
PARTITION p2 VALUES LESS THAN (1980),
PARTITION p3 VALUES LESS THAN (1990),
PARTITION p4 VALUES LESS THAN
MAXVALUE
);
MySQL Replication
Copyright Oracle Corporation 2012 28
Top used Feature in MySQL
Used for Scalability and HA
Write to one master
Read from many slaves, easily add more as
needed
Perfect for read/write intensive apps
Asynchronous as standard
Semi-Synchronous support added in MySQL 5.5
Each slave adds minimal load on master
Replication formats:
Statement-based replication (SBR): propagate
SQL statements
Row-based replication (RBR): propagate row
changes
Mixed-based replication: SBR or RBR depending
on the query
http://sqlhjalp.com/pdf/2012_Scale_Replication.pdf
MySQL Replication Overview
Copyright Oracle Corporation 2012 29
sqlhjalp.com/pdf/2012_Scale_Replication.pdf available for review
MySQL Replication Topologies
Copyright Oracle Corporation 2012 30
http://sqlhjalp.com/pdf/2012_Scale_Replication.pdf
MySQL Replication Overview
Copyright Oracle Corporation 2012 31
Replication Threads
Binlog dump thread
Slave I/O thread
Slave SQL thread
Replication Files
relay log
master info log
relay log info log
http://sqlhjalp.com/pdf/2012_Scale_Replication.pdf
MySQL Replication Overview
Copyright Oracle Corporation 2012 32
http://sqlhjalp.com/pdf/2012_Scale_Replication.pdf
MySQL Replication Overview
Copyright Oracle Corporation 2012 33
Oracle Integrations:
Golden Gate

Heterogeneous Replication between
MySQL, Oracle

MySQL specific optimizations

Hybrid web, enterprise applications
(Sabre Holdings)

Offload, scale query activity to MySQL
read-only slaves

Real-time access to web-based
analytics, reporting

Migration path from/to MySQL from
other databases with minimal downtime
MySQL Replication
Copyright Oracle Corporation 2012 34
Not on a cluster but MySQL Cluster
Different source tree, different versioning (7.x)
Developed from Erickson
In-memory, shared-nothing architecture
“Synchronous, multi-master replication”
Availability
99.999% (<5 min downtime / year)
Performance
Response Time 2-5 millisecond (with synchronous replication and access via NDB
API
Throughput of 10,000+ replicated transactions/sec on a 2 Node Cluster, with 1 CPU
Per Node (minimal configuration)
Throughput of 100,000 replicated transactions/sec on 4 Node Cluster, with 2 CPU
Per Node (low-end configuration)
Failover
Sub-second failover enables you to deliver service without interruption
MySQL Cluster
Copyright Oracle Corporation 2012 35
http://www.mysql.com/products/cluster/
Node Failure Detection & Self-Healing Recovery
MySQL Cluster
Copyright Oracle Corporation 2012 36
http://www.mysql.com/products/cluster/
The way depends on the application
Possible solutions:
Replication?
mysqldump
MySQL Enterprise Backup
Best solution is using all three.
# mysqldump -p --all-databases --master-data=1 >
/tmp/example_dump.sql
Not an online solution. Can/will lock tables.
MySQL Backup
http://www.amazon.com/Effective-MySQL-Backup-Recovery-Oracle/dp/0071788573
Copyright Oracle Corporation 2012 37

Online Backup for InnoDB

Support for MyISAM (Read-only)

High Performance Backup & Restore

Compressed Backup

Full Backup

Incremental Backup

Partial Backups

Point in Time Recovery

Unlimited Database Size

Cross-Platform

Windows, Linux, Unix
Ensures quick, online backup and recovery of your MySQL apps.
MySQL Enterprise Backup
Copyright Oracle Corporation 2012 38
Usage:
ibbackup [--incremental lsn] [--sleep ms] [--suspend-at-end] [--compress [level]] [--include regexp] my.cnf backup-
my.cnf
or
ibbackup --apply-log [--use-memory mb] [--uncompress] backup-my.cnf
or
ibbackup --apply-log --incremental [--use-memory mb] [--uncompress] incremental-backup-my.cnf full-backup-my.cnf
The backup program does NOT make a backup of the .frm files of the tables,
and it does not make backups of MyISAM tables. To back up these items, either:
- Use the mysqlbackup program.
- Make backups of the .frm files with the Unix 'tar' or the Windows WinZip or an equivalent tool both BEFORE and
AFTER ibbackup finishes its work,and also store the MySQL binlog segment that is generated between the
moment
you copy the .frm files to a backup and the moment ibbackup finishes its work.
For extra safety, also use:
mysqldump -l -d yourdatabasename
to dump the table CREATE statements in a human-readable form before
ibbackup finishes its work.
Copyright Oracle Corporation 2012 39
MySQL Enterprise Backup
• Familiarize with the key concepts
Session Agenda
Copyright Oracle Corporation 2012 40
MySQL products support unicode.
Full Unicode 5.0 is supported for data, and for metadata we
support only characters for Basic Multilingual Plane (BMP).
Database or schema in Oracle world.
Current database (per connection)
Database – a set of files in “the data directory”
System database (mysql)
Virtual databases:
INFORMATION_SCHEMA
PERFORMANCE_SCHEMA
MySQL Concepts
Copyright Oracle Corporation 2012 41
User: username@hostname
Precisely: ‘user-name-mask’@’host-name-mask’
Host name – client host name (“from” host name)
User name mask:
can be empty (anonymous user) – all users
Host name mask:
can be empty – all host names (%)
can have ‘%’ (e.g.: %.foo.com)
MySQL Privileges
Copyright Oracle Corporation 2012 42
Connecting as foo from localhost…
Should be foo@%, right ?
The most specific values are used
BUT: host name matching is done before user name
mysql -u foo -h localhost -p
‘’@localhost will be chosen !
MySQL Privileges
+-----------+-------------------+
| Host | User |
+-----------+-------------------+
| localhost | |
| localhost | bar |
| % | foo |
| localhost | root |
+-----------+-------------------+
Copyright Oracle Corporation 2012 43
$ mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using
password: NO)
$ mysql -u root -p
Enter password:
$ mysqladmin -u root -p password <passwordhere>
mysql> UPDATE mysql.user
SET Password=PASSWORD('<passwordhere>')
WHERE User='root';
mysql> FLUSH PRIVILEGES;
Copyright Oracle Corporation 2012 44
MySQL Privileges -- Root
Do not know the root password?
Stop the service: # /etc/init.d/mysql stop
Restart with skip grand: # mysqld_safe --skip-grant-tables &
Connect as root: # mysql -u root
Set new password :
use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-
PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
Stop the service: # /etc/init.d/mysql stop
Start the service: # /etc/init.d/mysql start
Log in as root with password. # mysql -u root -p
Copyright Oracle Corporation 2012 45
http://dev.mysql.com/doc/refman/5.5/en/resetting-permissions.html
MySQL Privileges
mysql> CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
mysql> GRANT ALTER, CREATE VIEW, CREATE, DELETE, DROP,
GRANT OPTION, INDEX, INSERT, SELECT, SHOW VIEW, TRIGGER,
UPDATE ON *.* TO 'monty'@'localhost'
WITH GRANT OPTION;
mysql> CREATE USER 'monty'@'%' IDENTIFIED BY 'some_pass';
mysql> GRANT ALTER, CREATE VIEW, CREATE, DELETE, DROP,
GRANT OPTION, INDEX, INSERT, SELECT, SHOW VIEW, TRIGGER,
UPDATE ON *.* TO 'monty'@'%'
WITH GRANT OPTION;
mysql> flush privileges ;
Copyright Oracle Corporation 2012 46
MySQL Privileges -- users
http://dev.mysql.com/doc/refman/5.6/en/grant.html
mysql> CREATE USER 'admin'@'localhost' IDENTIFIED BY 'admin_pass';
GRANT ALL ON *.* TO 'admin'@'localhost';
mysql> flush privileges ;
MySQL Super User Accounts
Copyright Oracle Corporation 2012 47
http://dev.mysql.com/doc/refman/5.6/en/grant.html
SHOW CREATE TABLE tbl_name
SHOW CREATE PROCEDURE proc_name
SHOW CREATE TRIGGER trigger_name
SHOW CREATE VIEW view_name
SHOW PROCEDURE CODE proc_name
SHOW PROCEDURE STATUS [like_or_where]
SHOW [FULL] PROCESSLIST
SHOW GRANTS [FOR user]
SHOW WARNINGS [LIMIT [offset,] row_count]
SHOW {DATABASES | SCHEMAS} [LIKE 'pattern' | WHERE expr]
SHOW OPEN TABLES [{FROM | IN} db_name] [LIKE 'pattern' | WHERE expr]
SHOW BINARY LOGS
SHOW MASTER LOGS
MySQL Show Commands
Copyright Oracle Corporation 2012 48
http://dev.mysql.com/doc/refman/5.6/en/show.html
Use SHOW processlist to find out what is going on:
+----+-------+-----------+----+---------+------+--------------+-------------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------+-----------+----+---------+------+--------------+-------------------------------------+
| 6 | monty | localhost | bp | Query | 15 | Sending data | select * from station,station as s1 |
| 8 | monty | localhost | | Query | 0 | | show processlist |
+----+-------+-----------+----+---------+------+--------------+-------------------------------------+
Use KILL in mysql or mysqladmin to kill off runaway threads.
How to find out how MySQL solves a query
Run the following commands and try to understand the output:
* SHOW VARIABLES;
* SHOW COLUMNS FROM ...G
* EXPLAIN SELECT ...G
* FLUSH STATUS;
* SELECT ...;
* SHOW STATUS;
MySQL Show Processlist
Copyright Oracle Corporation 2012 49
A few ways to see what databases you have on your system:
– cd /var/lib/mysql
• Review the directories
– Log in to MySQL server
• Show databases
– mysql -u root -p
» Enter password:
– show databases;
– +--------------------+
– | Database |
– +--------------------+
– | information_schema |
– | db_example |
– | employees |
– | exampledb |
– | mysql |
– | orig |
– | performance_schema |
– +--------------------+
MySQL Databases/Schema
Copyright Oracle Corporation 2012 50
mysql> use world; ---- DATABASE / SCHEMA
mysql> show tables; ---- TABLE SPACE
+-----------------+
| Tables_in_world |
+-----------------+
| City |
| Country |
| CountryLanguage |
+-----------------+
3 rows in set (0.00 sec)
MySQL Table Space
Copyright Oracle Corporation 2012 51
mysql> show create table City;
CREATE TABLE `City` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Name` char(35) NOT NULL DEFAULT '',
`CountryCode` char(3) NOT NULL DEFAULT '',
`District` char(20) NOT NULL DEFAULT '',
`Population` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`),
KEY `CountryCode` (`CountryCode`),
CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`) REFERENCES
`Country` (`Code`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1
Copyright Oracle Corporation 2012 52
MySQL Table Space
mysql > desc City;
+-------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+----------+------+-----+---------+----------------+
| ID | int(11) | NO | PRI | NULL | auto_increment |
| Name | char(35) | NO | | | |
| CountryCode | char(3) | NO | MUL | | |
| District | char(20) | NO | | | |
| Population | int(11) | NO | | 0 | |
+-------------+----------+------+-----+---------+----------------+
5 rows in set (0.06 sec)
Copyright Oracle Corporation 2012 53
MySQL Table Space
TEXT TYPES
CHAR( )A fixed section from 0 to 255 characters long.
VARCHAR( )A variable section from 0 to 255 characters long.
TINYTEXT A string with a maximum length of 255 characters.
TEXT A string with a maximum length of 65535 characters.
BLOB A string with a maximum length of 65535 characters.
MEDIUMTEXT A string with a maximum length of 16777215 characters.
MEDIUMBLOB A string with a maximum length of 16777215 characters.
LONGTEXT A string with a maximum length of 4294967295 characters.
LONGBLOB A string with a maximum length of 4294967295 characters.
CREATE TABLE `example_table` (
...
`value` varchar(100) DEFAULT NULL,
...
MySQL Datatypes
Copyright Oracle Corporation 2012 54
http://dev.mysql.com/doc/refman/5.5/en/data-types.html
NUMBER TYPES
TINYINT( ) -128 to 127 normal 0 to 255 UNSIGNED.
SMALLINT( ) -32768 to 32767 normal 0 to 65535 UNSIGNED.
MEDIUMINT( )-8388608 to 8388607 normal 0 to 16777215 UNSIGNED.
INT( ) -2147483648 to 2147483647 normal 0 to 4294967295 UNSIGNED.
BIGINT( )-9223372036854775808 to 9223372036854775807 normal
0 to 18446744073709551615 UNSIGNED.
FLOAT A small number with a floating decimal point.
DOUBLE( , ) A large number with a floating decimal point.
DECIMAL( , ) A DOUBLE stored as a string , allowing for a fixed decimal point.
Create Table: CREATE TABLE `example_table` (
`example_table_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
.....or
`example_table_id` bigint(12) unsigned NOT NULL auto_increment
Copyright Oracle Corporation 2012 55
http://dev.mysql.com/doc/refman/5.5/en/data-types.html
MySQL Datatypes
DATE TYPES
DATE YYYY-MM-DD.
DATETIME YYYY-MM-DD HH:MM:SS.
TIMESTAMP YYYYMMDDHHMMSS.
TIME HH:MM:SS.
Create Table: CREATE TABLE `example_table` (
`example_table_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(9) unsigned DEFAULT NULL,
`date_recorded` datetime DEFAULT NULL,
PRIMARY KEY (`example_table_id`),
UNIQUE KEY `user_id` (`user_id`),
KEY `date_recorded` (`date_recorded`)
) ENGINE=InnoDB
Copyright Oracle Corporation 2012 56
http://dev.mysql.com/doc/refman/5.5/en/data-types.html
MySQL Datatypes
MISC TYPES
ENUM ( ) Short for ENUMERATION which means that each column may
have one of a specified possible values.
SET Similar to ENUM except each column may have more than one of the
specified possible values.
…..
`transfer_method` enum('OFF','EMAIL','FTP','BATCH POST','FTP-SSL','REAL
TIME POST','CUSTOM') default NULL,
….
Copyright Oracle Corporation 2012 57
http://dev.mysql.com/doc/refman/5.5/en/data-types.html
MySQL Datatypes
URLS to help for later:
http://dev.mysql.com/doc/refman/5.6/en/mysql-indexes.html
http://dev.mysql.com/doc/refman/5.6/en/show-index.html
http://dev.mysql.com/doc/refman/5.6/en/create-index.html
http://learnmysql.blogspot.com/2010/11/mysql-query-and-index-tuning.html
http://www.slideshare.net/manikandakumar/mysql-query-and-index-tuning
http://www.slideshare.net/osscube/indexing-the-mysql-index-key-to-performance-tuning
http://effectivemysql.com/downloads/ImprovingPerformanceWithBetterIndexes-OOW-2011.pdf
http://prajwal-tuladhar.net.np/2009/09/23/474/things-you-should-know-about-mysql-index/
http://dev.mysql.com/doc/refman/5.5/en/innodb-monitors.html
http://dev.mysql.com/doc/refman/5.5/en/innodb-parameters.html
http://dev.mysql.com/doc/refman/5.5/en/innodb-buffer-pool.html
http://www.mysqlperformanceblog.com/2006/07/17/show-innodb-status-walk-through/
http://dev.mysql.com/doc/refman/5.5/en/server-parameters.html
http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_key_buffer_size
http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_table_open_cache
http://www.mysqlperformanceblog.com/2007/11/01/innodb-performance-optimization-basics/
http://www.mysqlperformanceblog.com/2007/11/03/choosing-innodb_buffer_pool_size/
MySQL Indexes
Index Cards' "DNA" By ayalan
http://prajwal-tuladhar.net.np/2009/09/23/474/things-you-should-know-about-mysql-index/
Copyright Oracle Corporation 2012 58
MySQL Index options
MySQL startup options
When tuning a MySQL server, the two most important variables to configure
are key_buffer_size and table_open_cache.
The buffer pool is for caching data and indexes in memory so set the
following to < 80% of the machine physical memory.
Important options are:
innodb_buffer_pool_size < 80% of memory. # default value is 8M
innodb_log_file_size=2G. #dependent on recovery speed required.
innodb_log_buffer_size=4M
innodb_thread_concurrency=8 # Default
innodb_flush_method=O_DIRECT # double buffering and swap are bad
# innodb_file_per_table #depends on how many tables used. Get the big picture 1st
.
Copyright Oracle Corporation 2012 59
MySQL Indexes (keys)
When MySQL uses indexes
Using >, >=, =, <, <=, IF NULL and BETWEEN on a key.
o SELECT * FROM table_name WHERE key_part1=1 and key_part2 > 5;
o SELECT * FROM table_name WHERE key_part1 IS NULL;
* When you use a LIKE that doesn't start with a wildcard.
o SELECT * FROM table_name WHERE key_part1 LIKE 'jani%'
* Retrieving rows from other tables when performing joins.
o SELECT * from t1,t2 where t1.col=t2.key_part
* Find the MAX() or MIN() value for a specific index.
o SELECT MIN(key_part2),MAX(key_part2) FROM table_name where
key_part1=10
* ORDER BY or GROUP BY on a prefix of a key.
o SELECT * FROM foo ORDER BY key_part1,key_part2,key_part3
* When all columns used in the query are part of one key.
o SELECT key_part3 FROM table_name WHERE key_part1=1
Copyright Oracle Corporation 2012 60
MySQL Indexes (keys)
When MySQL doesn't use an index
* Indexes are NOT used if MySQL can calculate that it will probably be faster to
scan the whole table.
For example if key_part1 is evenly distributed between 1 and 100, it's not good to use
an index in the following query:
o SELECT * FROM table_name where key_part1 > 1 and key_part1 < 90
* If you are using HEAP tables and you don't search on all key parts with =
* When you use ORDER BY on a HEAP table
* If you are not using the first key part
o SELECT * FROM table_name WHERE key_part2=1
* If you are using LIKE that starts with a wildcard
o SELECT * FROM table_name WHERE key_part1 LIKE '%jani%'
* When you search on one index and do an ORDER BY on another
o SELECT * from table_name WHERE key_part1 = # ORDER BY key2
Copyright Oracle Corporation 2012 61
MySQL Indexes (keys)
Optimizing tables
Use NOT NULL for columns which will not store null values. This is particularly
important for columns which you index.
`e_id` bigint(12) unsigned NOT NULL
Don't create indexes you are not going to use.
Use the fact that MySQL can search on a prefix of an index; If you have and INDEX
(a,b), you don't need an index on (a).
UNIQUE KEY `uq_id` (`u_id`,`q_id`),
KEY `q_id` (`q_id`),
Instead of creating an index on long CHAR/VARCHAR column, index just a prefix of
the column to save space.
CREATE TABLE `table_name` (
`hostname` char(255) NOT NULL,
KEY `hostname` (`hostname`(10))
) ENGINE=InnoDB
Copyright Oracle Corporation 2012 62
Use EXPLAIN on every query that you think is too slow!
mysql> explain select t3.DateOfAction, t1.TransactionID
-> from t1 join t2 join t3
-> where t2.ID = t1.TransactionID and t3.ID = t2.GroupID
-> order by t3.DateOfAction, t1.TransactionID;
+-------+--------+---------------+---------+---------+------------------+------+---------------------------------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+-------+--------+---------------+---------+---------+------------------+------+---------------------------------+
| t1 | ALL | NULL | NULL | NULL | NULL | 11 | Using temporary; Using filesort |
| t2 | ref | ID | ID | 4 | t1.TransactionID | 13 | |
| t3 | eq_ref | PRIMARY | PRIMARY | 4 | t2.GroupID | 1 | |
+-------+--------+---------------+---------+---------+------------------+------+---------------------------------+
Types ALL and range signal a potential problem.
MySQL Index – Use Explain!
Copyright Oracle Corporation 2012 63
mysql> EXPLAIN SELECT C.Name , T.Name FROM world.City C INNER JOIN
world.Country T ON C.CountryCode = T.Code;
+----+-------------+-------+------+---------------+-------------+---------+--------------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+-------------+---------+--------------+------+-------+
| 1 | SIMPLE | T | ALL | PRIMARY | NULL | NULL | NULL | 264 |
|
| 1 | SIMPLE | C | ref | CountryCode | CountryCode | 3 | world.T.Code | 8 |
|
+----+-------------+-------+------+---------------+-------------+---------+--------------+------+-------+
MySQL Index – Use Explain!
Copyright Oracle Corporation 2012 64
More Urls for you to use later about Explain
http://dev.mysql.com/doc/refman/5.5/en/explain.html
http://effectivemysql.com/downloads/ExplainingTheMySQLEXPLAIN-OOW-2011.pdf
http://prajwal-tuladhar.net.np/2009/09/26/481/know-more-about-mysql-explain/
http://www.slideshare.net/ligaya/explain
MySQL Index – Use Explain!
Copyright Oracle Corporation 2012 65
The CREATE ROUTINE , ALTER ROUTINE , EXECUTE privilege is needed for stored
routines.
mysql> delimiter //
mysql> CREATE PROCEDURE simpleproc (OUT param1 INT)
BEGIN
SELECT COUNT(*) INTO param1 FROM t;
END//
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
mysql> CALL simpleproc(@a);
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT @a;
+------+
| @a |
+------+
| 3 |
+------+
1 row in set (0.00 sec)
MySQL Stored Routines
Copyright Oracle Corporation 2012 66
http://dev.mysql.com/doc/refman/5.5/en/stored-routines.html
CREATE TABLE test1(a1 INT);
CREATE TABLE test2(a2 INT);
CREATE TABLE test3(a3 INT NOT NULL AUTO_INCREMENT PRIMARY KEY);
CREATE TABLE test4(
a4 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
b4 INT DEFAULT 0
);
delimiter |
CREATE TRIGGER testref BEFORE INSERT ON test1
FOR EACH ROW BEGIN
INSERT INTO test2 SET a2 = NEW.a1;
DELETE FROM test3 WHERE a3 = NEW.a1;
UPDATE test4 SET b4 = b4 + 1 WHERE a4 = NEW.a1;
END; |
delimiter ;
MySQL Triggers
Copyright Oracle Corporation 2012 67
http://dev.mysql.com/doc/refman/5.5/en/create-trigger.html
mysql> INSERT INTO test3 (a3)
VALUES (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL);
Query OK, 10 rows affected (0.04 sec)
Records: 10 Duplicates: 0 Warnings: 0
mysql> INSERT INTO test4 (a4) VALUES (0), (0), (0), (0), (0), (0), (0), (0), (0), (0);
Query OK, 10 rows affected (0.01 sec)
Records: 10 Duplicates: 0 Warnings: 0
INSERT INTO test1 VALUES (1), (3), (1), (7), (1), (8), (4), (4);
Query OK, 8 rows affected (0.01 sec)
Records: 8 Duplicates: 0 Warnings: 0
## Warnings: 1
Statement is unsafe because it invokes a trigger or a stored function that inserts into an
AUTO_INCREMENT column. Inserted values cannot be logged correctly.
set BINLOG_FORMAT = MIXED;
MySQL Triggers
Copyright Oracle Corporation 2012 68
http://dev.mysql.com/doc/refman/5.5/en/create-trigger.html
mysql> SELECT * FROM test1;
+------+
| a1 |
+------+
| 1 |
| 3 |
| 1 |
| 7 |
| 1 |
| 8 |
| 4 |
| 4 |
+------+
8 rows in set (0.00 sec)
MySQL Triggers
mysql> SELECT * FROM test3;
+----+
| a3 |
+----+
| 2 |
| 5 |
| 6 |
| 9 |
| 10 |
+----+
5 rows in set (0.00 sec)
mysql> SELECT * FROM test4;
+----+------+
| a4 | b4 |
+----+------+
| 1 | 3 |
| 2 | 0 |
| 3 | 1 |
| 4 | 2 |
| 5 | 0 |
| 6 | 0 |
| 7 | 1 |
| 8 | 1 |
| 9 | 0 |
| 10 | 0 |
+----+------+
10 rows in set (0.00 sec)
mysql> SELECT * FROM test2;
+------+
| a2 |
+------+
| 1 |
| 3 |
| 1 |
| 7 |
| 1 |
| 8 |
| 4 |
| 4 |
+------+
8 rows in set (0.00 s
Copyright Oracle Corporation 2012 69
http://dev.mysql.com/doc/refman/5.5/en/create-trigger.html
> CREATE VIEW `world`.`city_view` AS
SELECT C.Name as cityname , T.Name as countryname
FROM world.City C
INNER JOIN world.Country T ON C.CountryCode = T.Code;
Query OK, 0 rows affected (0.16 sec)
SELECT cityname , countryname from city_view where countryname = "Zimbabwe";
+--------------+-------------+
| cityname | countryname |
+--------------+-------------+
| Harare | Zimbabwe |
| Bulawayo | Zimbabwe |
| Chitungwiza | Zimbabwe |
| Mount Darwin | Zimbabwe |
| Mutare | Zimbabwe |
| Gweru | Zimbabwe |
+--------------+-------------+
6 rows in set (0.13 sec)
MySQL Views
Copyright Oracle Corporation 2012 70
http://dev.mysql.com/doc/refman/5.5/en/views.html
To disable autocommit mode, use the following statement:
mysql> show variables like '%autocommit%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| autocommit | ON |
+---------------+-------+
1 row in set (0.00 sec)
mysql> SET autocommit=0;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%autocommit%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| autocommit | OFF |
+---------------+-------+
1 row in set (0.01 sec)
MySQL Transactions
Copyright Oracle Corporation 2012 71
http://dev.mysql.com/doc/refman/5.5/en/commit.html
To disable autocommit mode for a single series of statements
use the START TRANSACTION statement:
START TRANSACTION;
SELECT @A:=SUM(salary) FROM table1 WHERE type=1;
UPDATE table2 SET summary=@A WHERE type=1;
COMMIT;
MySQL Transactions
Copyright Oracle Corporation 2012 72
http://dev.mysql.com/doc/refman/5.5/en/commit.html
• MySQL Editions
Session Agenda
Copyright Oracle Corporation 2012 73
Workbench – visual database design application that can be used to efficiently design,
manage and document database schemata
Connectors – ODBC, Java, .Net, MXJ, C/C++, DBI, Ruby, Python, etc.
Community: -- http://dev.mysql.com/downloads/
Freely downloadable version of the world's most popular open source database.
It is available under the GPL license and is supported by a huge and active
community of open source developers.
Enterprise: -- eDelivery.com (Free for 30 days)
Paid subscription includes support and the following
• MySQL Enterprise Backup
• MySQL Enterprise Security
– External Authentication
• MySQL Enterprise Scalability
– Thread Pool
• MySQL Enterprise High Availability
– Oracle VM Template
– Windows Clustering
• MySQL Enterprise Monitor
Free for 30 day evaluation
MySQL Versions
Copyright Oracle Corporation 2012 74
Choosing the version
5.1 – previous GA version
5.5 – the latest GA version
5.6 – development release
Choosing the edition
Community Edition (Community Server)
Enterprise Editions (even MySQL Classic and MySQL
Standard)
Source or Binary
Download
MySQL
Highly configurable
Command line options
Configuration files (plain-text, INI-like files with groups)
Several configuration files (/etc, $HOME, …)
The last value takes precedence
Default configuration are examples and might be not so good for
Performance, ...
MySQL Configuration
Copyright Oracle Corporation 2012 76
One example: SQL MODE
Very important variable
Affects data consistency!
It might be remembered …
… or it might be not
Thus: set it once for all
Recommended value:
STRICT_ALL_TABLES |
NO_ZERO_DATE |
NO_ZERO_IN_DATE |
NO_ENGINE_SUBSTITUTION |
NO_AUTO_CREATE_USER |
IGNORE_SPACE |
ERROR_FOR_DIVISION_BY_ZERO
Secure the installation
Don’t run under ‘root’
Have separate directories (configuration, data, binary
logs, …)
Change ‘root’ password
Remove default accounts
Post-installation steps: Security
MySQL
Copyright Oracle Corporation 2012 77
• Reach out to the community
– Irc on freenode
– Forums.mysql.com
• Oracle Support
• Certifications
How can I get help ?
MySQL Support
Copyright Oracle Corporation 2012 78Copyright Oracle Corporation 2012 78
• 24 X 7 Problem Resolution
Services
• Unlimited Support Incidents
• Knowledge Base
• Maintenance Releases, Bug
fixes, Patches, Updates
• MySQL Consultative Support
• Staffed by experienced,
seasoned MySQL Engineers
Oracle Premier Support for MySQL
MySQL Support
Most secure, scalable MySQL Database, Online Backup,
Development/Monitoring Tools, backed by Oracle Premier
Lifetime Support
Oracle Premier
Support
Oracle Product
Certifications/Integrations
MySQL Enterprise
High Availability
MySQL Enterprise
Security
MySQL Enterprise
Scalability
MySQL Enterprise
Backup
MySQL Enterprise
Monitor/Query Analyzer
MySQL Workbench
MySQL Enterprise Edition
Copyright Oracle Corporation 2012 80
mysql.com

TCO calculator: http://www.mysql.com/tcosavings/

White Papers: http://www.mysql.com/why-mysql/white-papers/

Customer use cases and success stories:
http://www.mysql.com/why-mysql/case-studies/
dev.mysql.com

Downloads: http://dev.mysql.com/downloads/

Documentation: http://dev.mysql.com/doc/

Forums: http://forums.mysql.com/

PlanetMySQL: http://planet.mysql.com

List of resources (books) : http://dev.mysql.com/resources/
MySQL Resources
eDelivery.com

Download and evaluate all MySQL products
Wiki:
https://wikis.oracle.com/display/mysql/Home
http://forge.mysql.com/wiki/Main_Page – Older Not used as much--
50 things to know before migrating Oracle to MySQL
It is a little old but worth the read
www.xaprb.com/blog/2009/03/13/50-things-to-know-before-migrating-oracle-to-mysql/
MySQL Resources
Copyright Oracle Corporation 2012 82
Copyright Oracle Corporation 2012 83
http://1.bp.blogspot.com/-WmD-
U4CwYwc/TwJIc4qp_hI/AAAAAAAAADY/Bj2_8cQFXOw/s1600/First_things_first_.jpg
http://www.techcn.com.cn/index.php?doc-view-131262.html
http://jeremylq.files.wordpress.com/2008/10/davidaxmark-larrysyacht-2005-08-15-l.jpg
http://blogs.oracle.com/barton808/entry/mysql_conf08_marten_mickos_tells
http://www.bytebot.net/blog/archives/2008/04/14/mysql-community-dinner-a-great-success
http://www.fayerwayer.com/2010/05/larry-ellison-critica-fuertemente-a-jonathan-schwartz/
http://www.devside.net/server/webdeveloper
http://www.curtoons.com/superman-logo/
http://systems.takizo.com/2009/08/23/how-to-remove-mysql-binary-log/
http://carlos.syr.edu/oracle-database-architecture/
http://images-4.findicons.com/files/icons/977/rrze/720/database_mysql.png
http://bhaveshvala.wordpress.com/2009/09/15/mysqls-blackhole-storage-engine/
http://www.erm.ecs.soton.ac.uk/theme3/managing_your_references.html
External Image Credits
Copyright Oracle Corporation 2012 84
<Insert Picture Here>
Thanks for attending!
keith.larson@oracle.com
http://sqlhjalp.com/pdf/MySQL_crashcourse_2012.pdf

Contenu connexe

Tendances

MySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMiguel Araújo
 
NoSQL and MySQL: News about JSON
NoSQL and MySQL: News about JSONNoSQL and MySQL: News about JSON
NoSQL and MySQL: News about JSONMario Beck
 
MySQL 5.7: What's New, Nov. 2015
MySQL 5.7: What's New, Nov. 2015MySQL 5.7: What's New, Nov. 2015
MySQL 5.7: What's New, Nov. 2015Mario Beck
 
MySQL for Software-as-a-Service (SaaS)
MySQL for Software-as-a-Service (SaaS)MySQL for Software-as-a-Service (SaaS)
MySQL for Software-as-a-Service (SaaS)Mario Beck
 
MySQL 5.7: Focus on InnoDB
MySQL 5.7: Focus on InnoDBMySQL 5.7: Focus on InnoDB
MySQL 5.7: Focus on InnoDBMario Beck
 
What's New in MySQL 8.0 @ HKOSC 2017
What's New in MySQL 8.0 @ HKOSC 2017What's New in MySQL 8.0 @ HKOSC 2017
What's New in MySQL 8.0 @ HKOSC 2017Ivan Ma
 
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017Ivan Ma
 
MySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellEmily Ikuta
 
MySQL Performance Best Practices
MySQL Performance Best PracticesMySQL Performance Best Practices
MySQL Performance Best PracticesOlivier DASINI
 
MySQL High Availability -- InnoDB Clusters
MySQL High Availability -- InnoDB ClustersMySQL High Availability -- InnoDB Clusters
MySQL High Availability -- InnoDB ClustersMatt Lord
 
Upgrade to MySQL 5.7 and latest news planned for MySQL 8
Upgrade to MySQL 5.7 and latest news planned for MySQL 8Upgrade to MySQL 5.7 and latest news planned for MySQL 8
Upgrade to MySQL 5.7 and latest news planned for MySQL 8Ted Wennmark
 
MySQL Security
MySQL SecurityMySQL Security
MySQL SecurityMario Beck
 
MySQL InnoDB Cluster and NDB Cluster
MySQL InnoDB Cluster and NDB ClusterMySQL InnoDB Cluster and NDB Cluster
MySQL InnoDB Cluster and NDB ClusterMario Beck
 
MySQL 5.7 Replication News
MySQL 5.7 Replication News MySQL 5.7 Replication News
MySQL 5.7 Replication News Ted Wennmark
 
MySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB Cluster
MySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB ClusterMySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB Cluster
MySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB ClusterOlivier DASINI
 
MySQL Document Store
MySQL Document StoreMySQL Document Store
MySQL Document StoreMario Beck
 
Introduction to MySQL
Introduction to MySQLIntroduction to MySQL
Introduction to MySQLTed Wennmark
 
2015: Whats New in MySQL 5.7, At Oracle Open World, November 3rd, 2015
2015: Whats New in MySQL 5.7, At Oracle Open World, November 3rd, 2015 2015: Whats New in MySQL 5.7, At Oracle Open World, November 3rd, 2015
2015: Whats New in MySQL 5.7, At Oracle Open World, November 3rd, 2015 Geir Høydalsvik
 
MySQL InnoDB Cluster - A complete High Availability solution for MySQL
MySQL InnoDB Cluster - A complete High Availability solution for MySQLMySQL InnoDB Cluster - A complete High Availability solution for MySQL
MySQL InnoDB Cluster - A complete High Availability solution for MySQLOlivier DASINI
 
MySQL 5.7: Focus on Replication
MySQL 5.7: Focus on ReplicationMySQL 5.7: Focus on Replication
MySQL 5.7: Focus on ReplicationMario Beck
 

Tendances (20)

MySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA Tool
 
NoSQL and MySQL: News about JSON
NoSQL and MySQL: News about JSONNoSQL and MySQL: News about JSON
NoSQL and MySQL: News about JSON
 
MySQL 5.7: What's New, Nov. 2015
MySQL 5.7: What's New, Nov. 2015MySQL 5.7: What's New, Nov. 2015
MySQL 5.7: What's New, Nov. 2015
 
MySQL for Software-as-a-Service (SaaS)
MySQL for Software-as-a-Service (SaaS)MySQL for Software-as-a-Service (SaaS)
MySQL for Software-as-a-Service (SaaS)
 
MySQL 5.7: Focus on InnoDB
MySQL 5.7: Focus on InnoDBMySQL 5.7: Focus on InnoDB
MySQL 5.7: Focus on InnoDB
 
What's New in MySQL 8.0 @ HKOSC 2017
What's New in MySQL 8.0 @ HKOSC 2017What's New in MySQL 8.0 @ HKOSC 2017
What's New in MySQL 8.0 @ HKOSC 2017
 
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
 
MySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a Nutshell
 
MySQL Performance Best Practices
MySQL Performance Best PracticesMySQL Performance Best Practices
MySQL Performance Best Practices
 
MySQL High Availability -- InnoDB Clusters
MySQL High Availability -- InnoDB ClustersMySQL High Availability -- InnoDB Clusters
MySQL High Availability -- InnoDB Clusters
 
Upgrade to MySQL 5.7 and latest news planned for MySQL 8
Upgrade to MySQL 5.7 and latest news planned for MySQL 8Upgrade to MySQL 5.7 and latest news planned for MySQL 8
Upgrade to MySQL 5.7 and latest news planned for MySQL 8
 
MySQL Security
MySQL SecurityMySQL Security
MySQL Security
 
MySQL InnoDB Cluster and NDB Cluster
MySQL InnoDB Cluster and NDB ClusterMySQL InnoDB Cluster and NDB Cluster
MySQL InnoDB Cluster and NDB Cluster
 
MySQL 5.7 Replication News
MySQL 5.7 Replication News MySQL 5.7 Replication News
MySQL 5.7 Replication News
 
MySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB Cluster
MySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB ClusterMySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB Cluster
MySQL Day Paris 2016 - MySQL HA: InnoDB Cluster and NDB Cluster
 
MySQL Document Store
MySQL Document StoreMySQL Document Store
MySQL Document Store
 
Introduction to MySQL
Introduction to MySQLIntroduction to MySQL
Introduction to MySQL
 
2015: Whats New in MySQL 5.7, At Oracle Open World, November 3rd, 2015
2015: Whats New in MySQL 5.7, At Oracle Open World, November 3rd, 2015 2015: Whats New in MySQL 5.7, At Oracle Open World, November 3rd, 2015
2015: Whats New in MySQL 5.7, At Oracle Open World, November 3rd, 2015
 
MySQL InnoDB Cluster - A complete High Availability solution for MySQL
MySQL InnoDB Cluster - A complete High Availability solution for MySQLMySQL InnoDB Cluster - A complete High Availability solution for MySQL
MySQL InnoDB Cluster - A complete High Availability solution for MySQL
 
MySQL 5.7: Focus on Replication
MySQL 5.7: Focus on ReplicationMySQL 5.7: Focus on Replication
MySQL 5.7: Focus on Replication
 

Similaire à My sql crashcourse_2012

MySQL For Oracle Developers
MySQL For Oracle DevelopersMySQL For Oracle Developers
MySQL For Oracle DevelopersRonald Bradford
 
MySQL 8: Ready for Prime Time
MySQL 8: Ready for Prime TimeMySQL 8: Ready for Prime Time
MySQL 8: Ready for Prime TimeArnab Ray
 
20191001 bkk-secret-of inno-db_clusterv1
20191001 bkk-secret-of inno-db_clusterv120191001 bkk-secret-of inno-db_clusterv1
20191001 bkk-secret-of inno-db_clusterv1Ivan Ma
 
20200613 my sql-ha-deployment
20200613 my sql-ha-deployment20200613 my sql-ha-deployment
20200613 my sql-ha-deploymentIvan Ma
 
My First 100 days with a MySQL DBMS (WP)
My First 100 days with a MySQL DBMS (WP)My First 100 days with a MySQL DBMS (WP)
My First 100 days with a MySQL DBMS (WP)Gustavo Rene Antunez
 
MySQL Ecosystem in 2020
MySQL Ecosystem in 2020MySQL Ecosystem in 2020
MySQL Ecosystem in 2020Alkin Tezuysal
 
Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.
Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.
Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.Geir Høydalsvik
 
Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014
Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014
Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014Manuel Contreras
 
Mysql User Camp : 20th June - Mysql New Features
Mysql User Camp : 20th June - Mysql New FeaturesMysql User Camp : 20th June - Mysql New Features
Mysql User Camp : 20th June - Mysql New FeaturesTarique Saleem
 
Mysql User Camp : 20-June-14 : Mysql New features and NoSQL Support
 Mysql User Camp : 20-June-14 : Mysql New features and NoSQL Support Mysql User Camp : 20-June-14 : Mysql New features and NoSQL Support
Mysql User Camp : 20-June-14 : Mysql New features and NoSQL SupportMysql User Camp
 
20090425mysqlslides 12593434194072-phpapp02
20090425mysqlslides 12593434194072-phpapp0220090425mysqlslides 12593434194072-phpapp02
20090425mysqlslides 12593434194072-phpapp02Vinamra Mittal
 
Ohio Linux Fest -- MySQL's NoSQL
Ohio Linux Fest -- MySQL's NoSQLOhio Linux Fest -- MySQL's NoSQL
Ohio Linux Fest -- MySQL's NoSQLDave Stokes
 
20190817 coscup-oracle my sql innodb cluster sharing
20190817 coscup-oracle my sql innodb cluster sharing20190817 coscup-oracle my sql innodb cluster sharing
20190817 coscup-oracle my sql innodb cluster sharingIvan Ma
 
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...GeneXus
 

Similaire à My sql crashcourse_2012 (20)

MySQL For Oracle Developers
MySQL For Oracle DevelopersMySQL For Oracle Developers
MySQL For Oracle Developers
 
MySQL 8: Ready for Prime Time
MySQL 8: Ready for Prime TimeMySQL 8: Ready for Prime Time
MySQL 8: Ready for Prime Time
 
20191001 bkk-secret-of inno-db_clusterv1
20191001 bkk-secret-of inno-db_clusterv120191001 bkk-secret-of inno-db_clusterv1
20191001 bkk-secret-of inno-db_clusterv1
 
20200613 my sql-ha-deployment
20200613 my sql-ha-deployment20200613 my sql-ha-deployment
20200613 my sql-ha-deployment
 
NoSQL and MySQL
NoSQL and MySQLNoSQL and MySQL
NoSQL and MySQL
 
My First 100 days with a MySQL DBMS (WP)
My First 100 days with a MySQL DBMS (WP)My First 100 days with a MySQL DBMS (WP)
My First 100 days with a MySQL DBMS (WP)
 
MySQL Ecosystem in 2020
MySQL Ecosystem in 2020MySQL Ecosystem in 2020
MySQL Ecosystem in 2020
 
Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.
Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.
Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.
 
Simple Way for MySQL to NoSQL
Simple Way for MySQL to NoSQLSimple Way for MySQL to NoSQL
Simple Way for MySQL to NoSQL
 
Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014
Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014
Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014
 
Mysql User Camp : 20th June - Mysql New Features
Mysql User Camp : 20th June - Mysql New FeaturesMysql User Camp : 20th June - Mysql New Features
Mysql User Camp : 20th June - Mysql New Features
 
Mysql User Camp : 20-June-14 : Mysql New features and NoSQL Support
 Mysql User Camp : 20-June-14 : Mysql New features and NoSQL Support Mysql User Camp : 20-June-14 : Mysql New features and NoSQL Support
Mysql User Camp : 20-June-14 : Mysql New features and NoSQL Support
 
20090425mysqlslides 12593434194072-phpapp02
20090425mysqlslides 12593434194072-phpapp0220090425mysqlslides 12593434194072-phpapp02
20090425mysqlslides 12593434194072-phpapp02
 
MySQL
MySQL MySQL
MySQL
 
Ohio Linux Fest -- MySQL's NoSQL
Ohio Linux Fest -- MySQL's NoSQLOhio Linux Fest -- MySQL's NoSQL
Ohio Linux Fest -- MySQL's NoSQL
 
20190817 coscup-oracle my sql innodb cluster sharing
20190817 coscup-oracle my sql innodb cluster sharing20190817 coscup-oracle my sql innodb cluster sharing
20190817 coscup-oracle my sql innodb cluster sharing
 
Sunshine php my sql 8.0 v2
Sunshine php my sql 8.0 v2Sunshine php my sql 8.0 v2
Sunshine php my sql 8.0 v2
 
Introduction to Mysql
Introduction to MysqlIntroduction to Mysql
Introduction to Mysql
 
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
 
My sql indo_comm
My sql indo_commMy sql indo_comm
My sql indo_comm
 

Dernier

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 

Dernier (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 

My sql crashcourse_2012

  • 1. <Insert Picture Here> MySQL: Crash Course Keith Larson keith.larson@oracle.com MySQL Community Manager http://sqlhjalp.com/pdf/MySQL_crashcourse_2012.pdf
  • 2. The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. Safe Harbor Statement
  • 3. Who am I and who are you? Keith Larson keith.larson@oracle.com MySQL Community Manager http://www.sqlhjalp.com/ Started with MySQL during the dot.com days. Primary real world work was with a MySQL InnoDB replicated chain environment that easily held over 4 billion rows of user data. Numerous other sites developed on LAMP stack over the last 13 years. Who are you? DBAs? Developers? Copyright Oracle Corporation 2012 3
  • 4. • Oracle's Investment into MySQL • A high-level overview • Familiarize with the key concepts • MySQL Editions Session Agenda Copyright Oracle Corporation 2012 4
  • 6. The official way to pronounce “MySQL” is “My Ess Que Ell” but we do not mind if you pronounce it as “my sequel” It was named after Monty's Daughter Maria. Pronunciation Copyright Oracle Corporation 2012 6
  • 7. Sakila is the official name of the MySQL dolphin (the logo). The name comes from a competition to name the dolphin. The winning name was submitted by Ambrose Twebaze, an Open Source software developer from Swaziland, Africa. According to Ambrose, the name Sakila has its roots in SiSwati, the local language of Swaziland. Sakila is also the name of a town in Arusha,Tanzania, near Ambrose's country of origin, Uganda. What do you think of when you think of a dolphin?  Fast  Love-able  Agile  Intelligent  Social  Everyone loves a dolphin What is Sakila? https://wikis.oracle.com/pages/viewpage.action?pageId=27394602 Copyright Oracle Corporation 2012 7
  • 8. MySQL AB founded 1995 by Michael Widenius, David Axmark, and Allan Larsson Initial release : 23 May 1995 Marten Mickos was CEO January 2001 to February 2008 2005 - Oracle Acquires Innobase (founded by Heikki Tuuri) A little background Copyright Oracle Corporation 2012 8
  • 9. Acquired by SUN Microsystems in 2008 for 1B USD Acquired by Oracle in 2009 Dual licensing: GPL v.2 + commercial Easy of use: the 15 minute rule has been cut down to 3 mins on windows “M” in “LAMP” stack A little background http://www.mysql.com/news-and-events/sun-to-acquire-mysql.html Marten Mickos CEO MySQL AB Jonathan Schwartz CEO SUN Larry Ellison CEO Oracle Copyright Oracle Corporation 2012 9
  • 10. • Oracle's Investment into MySQL Session Agenda Copyright Oracle Corporation 2012 10
  • 11. >70% of Oracle Shops run MySQL Copyright Oracle Corporation 2012 11  Fast  Agile  Ease of use  Scalable  Enterprise Ready
  • 12. Q2 CY2010 Q3 CY2010 Q4 CY2010 Q1 CY2011 • MySQL Workbench 5.2 GA! • MySQL Database 5.5 • MySQL Enterprise Backup 3.5 • MySQL Enterprise Monitor 2.3 • MySQL Cluster Manager 1.1 All GA! A Better MySQL Q2 CY2011 •MySQL Enterprise Monitor 2.2 •MySQL Cluster 7.1 • MySQL Cluster Manager 1.0 All GA! • MySQL Database 5.6 • MySQL Cluster 7.2 DMR* and MySQL Labs! (“early and often”) *Development Milestone Release Continuous Innovation with more product releases than ever before Copyright Oracle Corporation 2012 12
  • 13. MySQL On the Cover http://www.oracle.com/technetwork/issue-archive/2011/11-jan/index-191276.html Copyright Oracle Corporation 2012 13
  • 14. Enterprise 2.0SaaS, Cloud Web OEM / ISV’s Telecommunications Rely on MySQL Industry Leading Customers Copyright Oracle Corporation 2012 14
  • 15. • A high-level overview Session Agenda Copyright Oracle Corporation 2012 15
  • 16. MySQL Terminology • Database ( Files ) • Database Instance ( memory)memory • Schema • User • Table Space • Database Server Instance • Database Server Instance • Database • User • Table Space • Storage Engine Copyright Oracle Corporation 2012 16
  • 17. Error Log – log-error Binary Log – Log-bin custom set via my.cnf Slow Query Log – Log-slow-queries – Slow-query-time – log-queries-not-using-indexes General Log – Log http://dev.mysql.com/doc/refman/5.5/en/server-logs.html MySQL Logs Copyright Oracle Corporation 2012 17
  • 18. SHOW VARIABLES like '%log%'; +-----------------------------------------+-------------------------------------+ | Variable_name | Value | +-----------------------------------------+-------------------------------------+ | back_log | 50 | | binlog_cache_size | 32768 | | binlog_checksum | NONE | | binlog_direct_non_transactional_updates | OFF | | binlog_format | MIXED | | binlog_row_image | FULL | | binlog_rows_query_log_events | OFF | | binlog_stmt_cache_size | 32768 | | expire_logs_days | 0 | | general_log | OFF | | general_log_file | /var/lib/mysql/kdlarson-pc.log | …... Copyright Oracle Corporation 2012 18 MySQL Logs
  • 19. • Centralized monitoring of queries without Slow Query Log, SHOW PROCESSLIST; • Enabled via MySQL Connectors • Aggregated view of query execution counts, time, and rows • Visual “grab and go” correlation with Monitor graphs • Traces query executions back to source code Saves you time parsing atomic executions from logs. Finds problems you cannot find yourself. MySQL Query Analyzer Copyright Oracle Corporation 2012 19
  • 21. MySQL Database Architecture Copyright Oracle Corporation 2012 21
  • 22. Standalone (mysqld) UNIX daemon Windows service Regular process on UNIX or Windows Embedded (libmysqld) Shared / Dynamic library MySQL Server Copyright Oracle Corporation 2012 22
  • 23. InnoDB DB1 InnoDB DB2 MyISAM DB3 InnoDB MyISAM Core SQL-query processing, … Plugin 1 Plugin 2 Plugin 3 The Core Plugins Storage Engines Full-text search plugins Audit plugins Authentication plugins … MySQL Server Components Copyright Oracle Corporation 2012 23
  • 24. The Storage Engine (SE) defines data storage and retrieval Every regular table belongs to some SE Most notable Storage Engines: InnoDB (default since 5.5) – fully transactional SE MyISAM (default prior to 5.5) – NON-transactional SE Default Storage Engine used it not defined MySQL Storage Engines CREATE TABLE `City` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Name` char(35) NOT NULL DEFAULT '', `CountryCode` char(3) NOT NULL DEFAULT '', `District` char(20) NOT NULL DEFAULT '', `Population` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`), KEY `CountryCode` (`CountryCode`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 Copyright Oracle Corporation 2012 24
  • 25. Select a specialized storage engine for a particular application need. InnoDB: a high-reliability and high-performance storage engine for MySQL designed for transaction processing. It follows the ACID model. Row-level locking and Oracle-style consistent reads increase multi-user concurrency and performance MyISAM: -oldest storage engine has many features that have been developed over years. Memory: creates tables with contents that are stored in memory. MySQL Cluster offers the same features as the MEMORY engine with higher performance levels, and provides additional features MySQL Storage Engines Copyright Oracle Corporation 2012 25
  • 26. CSV: data file is a plain text file ARCHIVE: is used for storing large amounts of data without indexes in a very small footprint. BLACKHOLE:accepts data but throws it away and does not store it but the binary log is enabled. MySQL Storage Engines Copyright Oracle Corporation 2012 26
  • 27. Open Source Limitations Relating to Storage Engines Horizontal partitioning (distribute rows, not columns) Partitioning functions: The modulus Range Internal hashing function Linear hashing function MySQL Partitioning http://dev.mysql.com/doc/refman/5.1/en/partitioning-overview.html http://dev.mysql.com/tech-resources/articles/mysql_55_partitioning.html Copyright Oracle Corporation 2012 27 CREATE TABLE members ( firstname VARCHAR(25) NOT NULL, lastname VARCHAR(25) NOT NULL, username VARCHAR(16) NOT NULL, email VARCHAR(35), joined DATE NOT NULL ) PARTITION BY RANGE( YEAR(joined) ) ( PARTITION p0 VALUES LESS THAN (1960), PARTITION p1 VALUES LESS THAN (1970), PARTITION p2 VALUES LESS THAN (1980), PARTITION p3 VALUES LESS THAN (1990), PARTITION p4 VALUES LESS THAN MAXVALUE );
  • 28. MySQL Replication Copyright Oracle Corporation 2012 28
  • 29. Top used Feature in MySQL Used for Scalability and HA Write to one master Read from many slaves, easily add more as needed Perfect for read/write intensive apps Asynchronous as standard Semi-Synchronous support added in MySQL 5.5 Each slave adds minimal load on master Replication formats: Statement-based replication (SBR): propagate SQL statements Row-based replication (RBR): propagate row changes Mixed-based replication: SBR or RBR depending on the query http://sqlhjalp.com/pdf/2012_Scale_Replication.pdf MySQL Replication Overview Copyright Oracle Corporation 2012 29
  • 30. sqlhjalp.com/pdf/2012_Scale_Replication.pdf available for review MySQL Replication Topologies Copyright Oracle Corporation 2012 30
  • 31. http://sqlhjalp.com/pdf/2012_Scale_Replication.pdf MySQL Replication Overview Copyright Oracle Corporation 2012 31 Replication Threads Binlog dump thread Slave I/O thread Slave SQL thread Replication Files relay log master info log relay log info log
  • 34. Oracle Integrations: Golden Gate  Heterogeneous Replication between MySQL, Oracle  MySQL specific optimizations  Hybrid web, enterprise applications (Sabre Holdings)  Offload, scale query activity to MySQL read-only slaves  Real-time access to web-based analytics, reporting  Migration path from/to MySQL from other databases with minimal downtime MySQL Replication Copyright Oracle Corporation 2012 34
  • 35. Not on a cluster but MySQL Cluster Different source tree, different versioning (7.x) Developed from Erickson In-memory, shared-nothing architecture “Synchronous, multi-master replication” Availability 99.999% (<5 min downtime / year) Performance Response Time 2-5 millisecond (with synchronous replication and access via NDB API Throughput of 10,000+ replicated transactions/sec on a 2 Node Cluster, with 1 CPU Per Node (minimal configuration) Throughput of 100,000 replicated transactions/sec on 4 Node Cluster, with 2 CPU Per Node (low-end configuration) Failover Sub-second failover enables you to deliver service without interruption MySQL Cluster Copyright Oracle Corporation 2012 35 http://www.mysql.com/products/cluster/
  • 36. Node Failure Detection & Self-Healing Recovery MySQL Cluster Copyright Oracle Corporation 2012 36 http://www.mysql.com/products/cluster/
  • 37. The way depends on the application Possible solutions: Replication? mysqldump MySQL Enterprise Backup Best solution is using all three. # mysqldump -p --all-databases --master-data=1 > /tmp/example_dump.sql Not an online solution. Can/will lock tables. MySQL Backup http://www.amazon.com/Effective-MySQL-Backup-Recovery-Oracle/dp/0071788573 Copyright Oracle Corporation 2012 37
  • 38.  Online Backup for InnoDB  Support for MyISAM (Read-only)  High Performance Backup & Restore  Compressed Backup  Full Backup  Incremental Backup  Partial Backups  Point in Time Recovery  Unlimited Database Size  Cross-Platform  Windows, Linux, Unix Ensures quick, online backup and recovery of your MySQL apps. MySQL Enterprise Backup Copyright Oracle Corporation 2012 38
  • 39. Usage: ibbackup [--incremental lsn] [--sleep ms] [--suspend-at-end] [--compress [level]] [--include regexp] my.cnf backup- my.cnf or ibbackup --apply-log [--use-memory mb] [--uncompress] backup-my.cnf or ibbackup --apply-log --incremental [--use-memory mb] [--uncompress] incremental-backup-my.cnf full-backup-my.cnf The backup program does NOT make a backup of the .frm files of the tables, and it does not make backups of MyISAM tables. To back up these items, either: - Use the mysqlbackup program. - Make backups of the .frm files with the Unix 'tar' or the Windows WinZip or an equivalent tool both BEFORE and AFTER ibbackup finishes its work,and also store the MySQL binlog segment that is generated between the moment you copy the .frm files to a backup and the moment ibbackup finishes its work. For extra safety, also use: mysqldump -l -d yourdatabasename to dump the table CREATE statements in a human-readable form before ibbackup finishes its work. Copyright Oracle Corporation 2012 39 MySQL Enterprise Backup
  • 40. • Familiarize with the key concepts Session Agenda Copyright Oracle Corporation 2012 40
  • 41. MySQL products support unicode. Full Unicode 5.0 is supported for data, and for metadata we support only characters for Basic Multilingual Plane (BMP). Database or schema in Oracle world. Current database (per connection) Database – a set of files in “the data directory” System database (mysql) Virtual databases: INFORMATION_SCHEMA PERFORMANCE_SCHEMA MySQL Concepts Copyright Oracle Corporation 2012 41
  • 42. User: username@hostname Precisely: ‘user-name-mask’@’host-name-mask’ Host name – client host name (“from” host name) User name mask: can be empty (anonymous user) – all users Host name mask: can be empty – all host names (%) can have ‘%’ (e.g.: %.foo.com) MySQL Privileges Copyright Oracle Corporation 2012 42
  • 43. Connecting as foo from localhost… Should be foo@%, right ? The most specific values are used BUT: host name matching is done before user name mysql -u foo -h localhost -p ‘’@localhost will be chosen ! MySQL Privileges +-----------+-------------------+ | Host | User | +-----------+-------------------+ | localhost | | | localhost | bar | | % | foo | | localhost | root | +-----------+-------------------+ Copyright Oracle Corporation 2012 43
  • 44. $ mysql -u root ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) $ mysql -u root -p Enter password: $ mysqladmin -u root -p password <passwordhere> mysql> UPDATE mysql.user SET Password=PASSWORD('<passwordhere>') WHERE User='root'; mysql> FLUSH PRIVILEGES; Copyright Oracle Corporation 2012 44 MySQL Privileges -- Root
  • 45. Do not know the root password? Stop the service: # /etc/init.d/mysql stop Restart with skip grand: # mysqld_safe --skip-grant-tables & Connect as root: # mysql -u root Set new password : use mysql; mysql> update user set password=PASSWORD("NEW-ROOT- PASSWORD") where User='root'; mysql> flush privileges; mysql> quit Stop the service: # /etc/init.d/mysql stop Start the service: # /etc/init.d/mysql start Log in as root with password. # mysql -u root -p Copyright Oracle Corporation 2012 45 http://dev.mysql.com/doc/refman/5.5/en/resetting-permissions.html MySQL Privileges
  • 46. mysql> CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass'; mysql> GRANT ALTER, CREATE VIEW, CREATE, DELETE, DROP, GRANT OPTION, INDEX, INSERT, SELECT, SHOW VIEW, TRIGGER, UPDATE ON *.* TO 'monty'@'localhost' WITH GRANT OPTION; mysql> CREATE USER 'monty'@'%' IDENTIFIED BY 'some_pass'; mysql> GRANT ALTER, CREATE VIEW, CREATE, DELETE, DROP, GRANT OPTION, INDEX, INSERT, SELECT, SHOW VIEW, TRIGGER, UPDATE ON *.* TO 'monty'@'%' WITH GRANT OPTION; mysql> flush privileges ; Copyright Oracle Corporation 2012 46 MySQL Privileges -- users http://dev.mysql.com/doc/refman/5.6/en/grant.html
  • 47. mysql> CREATE USER 'admin'@'localhost' IDENTIFIED BY 'admin_pass'; GRANT ALL ON *.* TO 'admin'@'localhost'; mysql> flush privileges ; MySQL Super User Accounts Copyright Oracle Corporation 2012 47 http://dev.mysql.com/doc/refman/5.6/en/grant.html
  • 48. SHOW CREATE TABLE tbl_name SHOW CREATE PROCEDURE proc_name SHOW CREATE TRIGGER trigger_name SHOW CREATE VIEW view_name SHOW PROCEDURE CODE proc_name SHOW PROCEDURE STATUS [like_or_where] SHOW [FULL] PROCESSLIST SHOW GRANTS [FOR user] SHOW WARNINGS [LIMIT [offset,] row_count] SHOW {DATABASES | SCHEMAS} [LIKE 'pattern' | WHERE expr] SHOW OPEN TABLES [{FROM | IN} db_name] [LIKE 'pattern' | WHERE expr] SHOW BINARY LOGS SHOW MASTER LOGS MySQL Show Commands Copyright Oracle Corporation 2012 48 http://dev.mysql.com/doc/refman/5.6/en/show.html
  • 49. Use SHOW processlist to find out what is going on: +----+-------+-----------+----+---------+------+--------------+-------------------------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+-------+-----------+----+---------+------+--------------+-------------------------------------+ | 6 | monty | localhost | bp | Query | 15 | Sending data | select * from station,station as s1 | | 8 | monty | localhost | | Query | 0 | | show processlist | +----+-------+-----------+----+---------+------+--------------+-------------------------------------+ Use KILL in mysql or mysqladmin to kill off runaway threads. How to find out how MySQL solves a query Run the following commands and try to understand the output: * SHOW VARIABLES; * SHOW COLUMNS FROM ...G * EXPLAIN SELECT ...G * FLUSH STATUS; * SELECT ...; * SHOW STATUS; MySQL Show Processlist Copyright Oracle Corporation 2012 49
  • 50. A few ways to see what databases you have on your system: – cd /var/lib/mysql • Review the directories – Log in to MySQL server • Show databases – mysql -u root -p » Enter password: – show databases; – +--------------------+ – | Database | – +--------------------+ – | information_schema | – | db_example | – | employees | – | exampledb | – | mysql | – | orig | – | performance_schema | – +--------------------+ MySQL Databases/Schema Copyright Oracle Corporation 2012 50
  • 51. mysql> use world; ---- DATABASE / SCHEMA mysql> show tables; ---- TABLE SPACE +-----------------+ | Tables_in_world | +-----------------+ | City | | Country | | CountryLanguage | +-----------------+ 3 rows in set (0.00 sec) MySQL Table Space Copyright Oracle Corporation 2012 51
  • 52. mysql> show create table City; CREATE TABLE `City` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Name` char(35) NOT NULL DEFAULT '', `CountryCode` char(3) NOT NULL DEFAULT '', `District` char(20) NOT NULL DEFAULT '', `Population` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`), KEY `CountryCode` (`CountryCode`), CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`) REFERENCES `Country` (`Code`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 Copyright Oracle Corporation 2012 52 MySQL Table Space
  • 53. mysql > desc City; +-------------+----------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+----------+------+-----+---------+----------------+ | ID | int(11) | NO | PRI | NULL | auto_increment | | Name | char(35) | NO | | | | | CountryCode | char(3) | NO | MUL | | | | District | char(20) | NO | | | | | Population | int(11) | NO | | 0 | | +-------------+----------+------+-----+---------+----------------+ 5 rows in set (0.06 sec) Copyright Oracle Corporation 2012 53 MySQL Table Space
  • 54. TEXT TYPES CHAR( )A fixed section from 0 to 255 characters long. VARCHAR( )A variable section from 0 to 255 characters long. TINYTEXT A string with a maximum length of 255 characters. TEXT A string with a maximum length of 65535 characters. BLOB A string with a maximum length of 65535 characters. MEDIUMTEXT A string with a maximum length of 16777215 characters. MEDIUMBLOB A string with a maximum length of 16777215 characters. LONGTEXT A string with a maximum length of 4294967295 characters. LONGBLOB A string with a maximum length of 4294967295 characters. CREATE TABLE `example_table` ( ... `value` varchar(100) DEFAULT NULL, ... MySQL Datatypes Copyright Oracle Corporation 2012 54 http://dev.mysql.com/doc/refman/5.5/en/data-types.html
  • 55. NUMBER TYPES TINYINT( ) -128 to 127 normal 0 to 255 UNSIGNED. SMALLINT( ) -32768 to 32767 normal 0 to 65535 UNSIGNED. MEDIUMINT( )-8388608 to 8388607 normal 0 to 16777215 UNSIGNED. INT( ) -2147483648 to 2147483647 normal 0 to 4294967295 UNSIGNED. BIGINT( )-9223372036854775808 to 9223372036854775807 normal 0 to 18446744073709551615 UNSIGNED. FLOAT A small number with a floating decimal point. DOUBLE( , ) A large number with a floating decimal point. DECIMAL( , ) A DOUBLE stored as a string , allowing for a fixed decimal point. Create Table: CREATE TABLE `example_table` ( `example_table_id` int(10) unsigned NOT NULL AUTO_INCREMENT, .....or `example_table_id` bigint(12) unsigned NOT NULL auto_increment Copyright Oracle Corporation 2012 55 http://dev.mysql.com/doc/refman/5.5/en/data-types.html MySQL Datatypes
  • 56. DATE TYPES DATE YYYY-MM-DD. DATETIME YYYY-MM-DD HH:MM:SS. TIMESTAMP YYYYMMDDHHMMSS. TIME HH:MM:SS. Create Table: CREATE TABLE `example_table` ( `example_table_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `user_id` int(9) unsigned DEFAULT NULL, `date_recorded` datetime DEFAULT NULL, PRIMARY KEY (`example_table_id`), UNIQUE KEY `user_id` (`user_id`), KEY `date_recorded` (`date_recorded`) ) ENGINE=InnoDB Copyright Oracle Corporation 2012 56 http://dev.mysql.com/doc/refman/5.5/en/data-types.html MySQL Datatypes
  • 57. MISC TYPES ENUM ( ) Short for ENUMERATION which means that each column may have one of a specified possible values. SET Similar to ENUM except each column may have more than one of the specified possible values. ….. `transfer_method` enum('OFF','EMAIL','FTP','BATCH POST','FTP-SSL','REAL TIME POST','CUSTOM') default NULL, …. Copyright Oracle Corporation 2012 57 http://dev.mysql.com/doc/refman/5.5/en/data-types.html MySQL Datatypes
  • 58. URLS to help for later: http://dev.mysql.com/doc/refman/5.6/en/mysql-indexes.html http://dev.mysql.com/doc/refman/5.6/en/show-index.html http://dev.mysql.com/doc/refman/5.6/en/create-index.html http://learnmysql.blogspot.com/2010/11/mysql-query-and-index-tuning.html http://www.slideshare.net/manikandakumar/mysql-query-and-index-tuning http://www.slideshare.net/osscube/indexing-the-mysql-index-key-to-performance-tuning http://effectivemysql.com/downloads/ImprovingPerformanceWithBetterIndexes-OOW-2011.pdf http://prajwal-tuladhar.net.np/2009/09/23/474/things-you-should-know-about-mysql-index/ http://dev.mysql.com/doc/refman/5.5/en/innodb-monitors.html http://dev.mysql.com/doc/refman/5.5/en/innodb-parameters.html http://dev.mysql.com/doc/refman/5.5/en/innodb-buffer-pool.html http://www.mysqlperformanceblog.com/2006/07/17/show-innodb-status-walk-through/ http://dev.mysql.com/doc/refman/5.5/en/server-parameters.html http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_key_buffer_size http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_table_open_cache http://www.mysqlperformanceblog.com/2007/11/01/innodb-performance-optimization-basics/ http://www.mysqlperformanceblog.com/2007/11/03/choosing-innodb_buffer_pool_size/ MySQL Indexes Index Cards' "DNA" By ayalan http://prajwal-tuladhar.net.np/2009/09/23/474/things-you-should-know-about-mysql-index/ Copyright Oracle Corporation 2012 58
  • 59. MySQL Index options MySQL startup options When tuning a MySQL server, the two most important variables to configure are key_buffer_size and table_open_cache. The buffer pool is for caching data and indexes in memory so set the following to < 80% of the machine physical memory. Important options are: innodb_buffer_pool_size < 80% of memory. # default value is 8M innodb_log_file_size=2G. #dependent on recovery speed required. innodb_log_buffer_size=4M innodb_thread_concurrency=8 # Default innodb_flush_method=O_DIRECT # double buffering and swap are bad # innodb_file_per_table #depends on how many tables used. Get the big picture 1st . Copyright Oracle Corporation 2012 59
  • 60. MySQL Indexes (keys) When MySQL uses indexes Using >, >=, =, <, <=, IF NULL and BETWEEN on a key. o SELECT * FROM table_name WHERE key_part1=1 and key_part2 > 5; o SELECT * FROM table_name WHERE key_part1 IS NULL; * When you use a LIKE that doesn't start with a wildcard. o SELECT * FROM table_name WHERE key_part1 LIKE 'jani%' * Retrieving rows from other tables when performing joins. o SELECT * from t1,t2 where t1.col=t2.key_part * Find the MAX() or MIN() value for a specific index. o SELECT MIN(key_part2),MAX(key_part2) FROM table_name where key_part1=10 * ORDER BY or GROUP BY on a prefix of a key. o SELECT * FROM foo ORDER BY key_part1,key_part2,key_part3 * When all columns used in the query are part of one key. o SELECT key_part3 FROM table_name WHERE key_part1=1 Copyright Oracle Corporation 2012 60
  • 61. MySQL Indexes (keys) When MySQL doesn't use an index * Indexes are NOT used if MySQL can calculate that it will probably be faster to scan the whole table. For example if key_part1 is evenly distributed between 1 and 100, it's not good to use an index in the following query: o SELECT * FROM table_name where key_part1 > 1 and key_part1 < 90 * If you are using HEAP tables and you don't search on all key parts with = * When you use ORDER BY on a HEAP table * If you are not using the first key part o SELECT * FROM table_name WHERE key_part2=1 * If you are using LIKE that starts with a wildcard o SELECT * FROM table_name WHERE key_part1 LIKE '%jani%' * When you search on one index and do an ORDER BY on another o SELECT * from table_name WHERE key_part1 = # ORDER BY key2 Copyright Oracle Corporation 2012 61
  • 62. MySQL Indexes (keys) Optimizing tables Use NOT NULL for columns which will not store null values. This is particularly important for columns which you index. `e_id` bigint(12) unsigned NOT NULL Don't create indexes you are not going to use. Use the fact that MySQL can search on a prefix of an index; If you have and INDEX (a,b), you don't need an index on (a). UNIQUE KEY `uq_id` (`u_id`,`q_id`), KEY `q_id` (`q_id`), Instead of creating an index on long CHAR/VARCHAR column, index just a prefix of the column to save space. CREATE TABLE `table_name` ( `hostname` char(255) NOT NULL, KEY `hostname` (`hostname`(10)) ) ENGINE=InnoDB Copyright Oracle Corporation 2012 62
  • 63. Use EXPLAIN on every query that you think is too slow! mysql> explain select t3.DateOfAction, t1.TransactionID -> from t1 join t2 join t3 -> where t2.ID = t1.TransactionID and t3.ID = t2.GroupID -> order by t3.DateOfAction, t1.TransactionID; +-------+--------+---------------+---------+---------+------------------+------+---------------------------------+ | table | type | possible_keys | key | key_len | ref | rows | Extra | +-------+--------+---------------+---------+---------+------------------+------+---------------------------------+ | t1 | ALL | NULL | NULL | NULL | NULL | 11 | Using temporary; Using filesort | | t2 | ref | ID | ID | 4 | t1.TransactionID | 13 | | | t3 | eq_ref | PRIMARY | PRIMARY | 4 | t2.GroupID | 1 | | +-------+--------+---------------+---------+---------+------------------+------+---------------------------------+ Types ALL and range signal a potential problem. MySQL Index – Use Explain! Copyright Oracle Corporation 2012 63
  • 64. mysql> EXPLAIN SELECT C.Name , T.Name FROM world.City C INNER JOIN world.Country T ON C.CountryCode = T.Code; +----+-------------+-------+------+---------------+-------------+---------+--------------+------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+------+---------------+-------------+---------+--------------+------+-------+ | 1 | SIMPLE | T | ALL | PRIMARY | NULL | NULL | NULL | 264 | | | 1 | SIMPLE | C | ref | CountryCode | CountryCode | 3 | world.T.Code | 8 | | +----+-------------+-------+------+---------------+-------------+---------+--------------+------+-------+ MySQL Index – Use Explain! Copyright Oracle Corporation 2012 64
  • 65. More Urls for you to use later about Explain http://dev.mysql.com/doc/refman/5.5/en/explain.html http://effectivemysql.com/downloads/ExplainingTheMySQLEXPLAIN-OOW-2011.pdf http://prajwal-tuladhar.net.np/2009/09/26/481/know-more-about-mysql-explain/ http://www.slideshare.net/ligaya/explain MySQL Index – Use Explain! Copyright Oracle Corporation 2012 65
  • 66. The CREATE ROUTINE , ALTER ROUTINE , EXECUTE privilege is needed for stored routines. mysql> delimiter // mysql> CREATE PROCEDURE simpleproc (OUT param1 INT) BEGIN SELECT COUNT(*) INTO param1 FROM t; END// Query OK, 0 rows affected (0.00 sec) mysql> delimiter ; mysql> CALL simpleproc(@a); Query OK, 0 rows affected (0.00 sec) mysql> SELECT @a; +------+ | @a | +------+ | 3 | +------+ 1 row in set (0.00 sec) MySQL Stored Routines Copyright Oracle Corporation 2012 66 http://dev.mysql.com/doc/refman/5.5/en/stored-routines.html
  • 67. CREATE TABLE test1(a1 INT); CREATE TABLE test2(a2 INT); CREATE TABLE test3(a3 INT NOT NULL AUTO_INCREMENT PRIMARY KEY); CREATE TABLE test4( a4 INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b4 INT DEFAULT 0 ); delimiter | CREATE TRIGGER testref BEFORE INSERT ON test1 FOR EACH ROW BEGIN INSERT INTO test2 SET a2 = NEW.a1; DELETE FROM test3 WHERE a3 = NEW.a1; UPDATE test4 SET b4 = b4 + 1 WHERE a4 = NEW.a1; END; | delimiter ; MySQL Triggers Copyright Oracle Corporation 2012 67 http://dev.mysql.com/doc/refman/5.5/en/create-trigger.html
  • 68. mysql> INSERT INTO test3 (a3) VALUES (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL); Query OK, 10 rows affected (0.04 sec) Records: 10 Duplicates: 0 Warnings: 0 mysql> INSERT INTO test4 (a4) VALUES (0), (0), (0), (0), (0), (0), (0), (0), (0), (0); Query OK, 10 rows affected (0.01 sec) Records: 10 Duplicates: 0 Warnings: 0 INSERT INTO test1 VALUES (1), (3), (1), (7), (1), (8), (4), (4); Query OK, 8 rows affected (0.01 sec) Records: 8 Duplicates: 0 Warnings: 0 ## Warnings: 1 Statement is unsafe because it invokes a trigger or a stored function that inserts into an AUTO_INCREMENT column. Inserted values cannot be logged correctly. set BINLOG_FORMAT = MIXED; MySQL Triggers Copyright Oracle Corporation 2012 68 http://dev.mysql.com/doc/refman/5.5/en/create-trigger.html
  • 69. mysql> SELECT * FROM test1; +------+ | a1 | +------+ | 1 | | 3 | | 1 | | 7 | | 1 | | 8 | | 4 | | 4 | +------+ 8 rows in set (0.00 sec) MySQL Triggers mysql> SELECT * FROM test3; +----+ | a3 | +----+ | 2 | | 5 | | 6 | | 9 | | 10 | +----+ 5 rows in set (0.00 sec) mysql> SELECT * FROM test4; +----+------+ | a4 | b4 | +----+------+ | 1 | 3 | | 2 | 0 | | 3 | 1 | | 4 | 2 | | 5 | 0 | | 6 | 0 | | 7 | 1 | | 8 | 1 | | 9 | 0 | | 10 | 0 | +----+------+ 10 rows in set (0.00 sec) mysql> SELECT * FROM test2; +------+ | a2 | +------+ | 1 | | 3 | | 1 | | 7 | | 1 | | 8 | | 4 | | 4 | +------+ 8 rows in set (0.00 s Copyright Oracle Corporation 2012 69 http://dev.mysql.com/doc/refman/5.5/en/create-trigger.html
  • 70. > CREATE VIEW `world`.`city_view` AS SELECT C.Name as cityname , T.Name as countryname FROM world.City C INNER JOIN world.Country T ON C.CountryCode = T.Code; Query OK, 0 rows affected (0.16 sec) SELECT cityname , countryname from city_view where countryname = "Zimbabwe"; +--------------+-------------+ | cityname | countryname | +--------------+-------------+ | Harare | Zimbabwe | | Bulawayo | Zimbabwe | | Chitungwiza | Zimbabwe | | Mount Darwin | Zimbabwe | | Mutare | Zimbabwe | | Gweru | Zimbabwe | +--------------+-------------+ 6 rows in set (0.13 sec) MySQL Views Copyright Oracle Corporation 2012 70 http://dev.mysql.com/doc/refman/5.5/en/views.html
  • 71. To disable autocommit mode, use the following statement: mysql> show variables like '%autocommit%'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | autocommit | ON | +---------------+-------+ 1 row in set (0.00 sec) mysql> SET autocommit=0; Query OK, 0 rows affected (0.00 sec) mysql> show variables like '%autocommit%'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | autocommit | OFF | +---------------+-------+ 1 row in set (0.01 sec) MySQL Transactions Copyright Oracle Corporation 2012 71 http://dev.mysql.com/doc/refman/5.5/en/commit.html
  • 72. To disable autocommit mode for a single series of statements use the START TRANSACTION statement: START TRANSACTION; SELECT @A:=SUM(salary) FROM table1 WHERE type=1; UPDATE table2 SET summary=@A WHERE type=1; COMMIT; MySQL Transactions Copyright Oracle Corporation 2012 72 http://dev.mysql.com/doc/refman/5.5/en/commit.html
  • 73. • MySQL Editions Session Agenda Copyright Oracle Corporation 2012 73
  • 74. Workbench – visual database design application that can be used to efficiently design, manage and document database schemata Connectors – ODBC, Java, .Net, MXJ, C/C++, DBI, Ruby, Python, etc. Community: -- http://dev.mysql.com/downloads/ Freely downloadable version of the world's most popular open source database. It is available under the GPL license and is supported by a huge and active community of open source developers. Enterprise: -- eDelivery.com (Free for 30 days) Paid subscription includes support and the following • MySQL Enterprise Backup • MySQL Enterprise Security – External Authentication • MySQL Enterprise Scalability – Thread Pool • MySQL Enterprise High Availability – Oracle VM Template – Windows Clustering • MySQL Enterprise Monitor Free for 30 day evaluation MySQL Versions Copyright Oracle Corporation 2012 74
  • 75. Choosing the version 5.1 – previous GA version 5.5 – the latest GA version 5.6 – development release Choosing the edition Community Edition (Community Server) Enterprise Editions (even MySQL Classic and MySQL Standard) Source or Binary Download MySQL
  • 76. Highly configurable Command line options Configuration files (plain-text, INI-like files with groups) Several configuration files (/etc, $HOME, …) The last value takes precedence Default configuration are examples and might be not so good for Performance, ... MySQL Configuration Copyright Oracle Corporation 2012 76 One example: SQL MODE Very important variable Affects data consistency! It might be remembered … … or it might be not Thus: set it once for all Recommended value: STRICT_ALL_TABLES | NO_ZERO_DATE | NO_ZERO_IN_DATE | NO_ENGINE_SUBSTITUTION | NO_AUTO_CREATE_USER | IGNORE_SPACE | ERROR_FOR_DIVISION_BY_ZERO
  • 77. Secure the installation Don’t run under ‘root’ Have separate directories (configuration, data, binary logs, …) Change ‘root’ password Remove default accounts Post-installation steps: Security MySQL Copyright Oracle Corporation 2012 77
  • 78. • Reach out to the community – Irc on freenode – Forums.mysql.com • Oracle Support • Certifications How can I get help ? MySQL Support Copyright Oracle Corporation 2012 78Copyright Oracle Corporation 2012 78
  • 79. • 24 X 7 Problem Resolution Services • Unlimited Support Incidents • Knowledge Base • Maintenance Releases, Bug fixes, Patches, Updates • MySQL Consultative Support • Staffed by experienced, seasoned MySQL Engineers Oracle Premier Support for MySQL MySQL Support
  • 80. Most secure, scalable MySQL Database, Online Backup, Development/Monitoring Tools, backed by Oracle Premier Lifetime Support Oracle Premier Support Oracle Product Certifications/Integrations MySQL Enterprise High Availability MySQL Enterprise Security MySQL Enterprise Scalability MySQL Enterprise Backup MySQL Enterprise Monitor/Query Analyzer MySQL Workbench MySQL Enterprise Edition Copyright Oracle Corporation 2012 80
  • 81. mysql.com  TCO calculator: http://www.mysql.com/tcosavings/  White Papers: http://www.mysql.com/why-mysql/white-papers/  Customer use cases and success stories: http://www.mysql.com/why-mysql/case-studies/ dev.mysql.com  Downloads: http://dev.mysql.com/downloads/  Documentation: http://dev.mysql.com/doc/  Forums: http://forums.mysql.com/  PlanetMySQL: http://planet.mysql.com  List of resources (books) : http://dev.mysql.com/resources/ MySQL Resources
  • 82. eDelivery.com  Download and evaluate all MySQL products Wiki: https://wikis.oracle.com/display/mysql/Home http://forge.mysql.com/wiki/Main_Page – Older Not used as much-- 50 things to know before migrating Oracle to MySQL It is a little old but worth the read www.xaprb.com/blog/2009/03/13/50-things-to-know-before-migrating-oracle-to-mysql/ MySQL Resources Copyright Oracle Corporation 2012 82
  • 84. http://1.bp.blogspot.com/-WmD- U4CwYwc/TwJIc4qp_hI/AAAAAAAAADY/Bj2_8cQFXOw/s1600/First_things_first_.jpg http://www.techcn.com.cn/index.php?doc-view-131262.html http://jeremylq.files.wordpress.com/2008/10/davidaxmark-larrysyacht-2005-08-15-l.jpg http://blogs.oracle.com/barton808/entry/mysql_conf08_marten_mickos_tells http://www.bytebot.net/blog/archives/2008/04/14/mysql-community-dinner-a-great-success http://www.fayerwayer.com/2010/05/larry-ellison-critica-fuertemente-a-jonathan-schwartz/ http://www.devside.net/server/webdeveloper http://www.curtoons.com/superman-logo/ http://systems.takizo.com/2009/08/23/how-to-remove-mysql-binary-log/ http://carlos.syr.edu/oracle-database-architecture/ http://images-4.findicons.com/files/icons/977/rrze/720/database_mysql.png http://bhaveshvala.wordpress.com/2009/09/15/mysqls-blackhole-storage-engine/ http://www.erm.ecs.soton.ac.uk/theme3/managing_your_references.html External Image Credits Copyright Oracle Corporation 2012 84
  • 85. <Insert Picture Here> Thanks for attending! keith.larson@oracle.com http://sqlhjalp.com/pdf/MySQL_crashcourse_2012.pdf