You are on page 1of 47

1

<Insert Picture Here>


MySQL for Java Developers
Pavan Venkatesh
Senior Sales Consultant
3
AGENDA

MySQL Overview

MySQL Connectors overview

Connector/J

Load Balancing and Failover examples

Connector MXJ

XML support

MySQL 5.5 and Enterprise tools

MySQL 5.6 DM
4
Overview of MySQL

12 million product installations

Over 100 million copies downloaded worldwide

Over 70,000 downloads each day

Sun acquired MySQL in April 2008

Oracle completed Sun acquisition in February 2010

Majority of Oracle customers also use MySQL


5
MySQL:
The Worlds Leading On-Line Database
Powering 9 of the top 10 most trafficked sites on the web*
6
Oracles Investment in MySQL
Rapid Innovation

#1 Open Source Database for Web Applications

Most Complete LAMP Stack

Telecom & Embedded

Improve engineering, consulting and support

Leverage 24x7, World-Class Oracle Support

Source and binary releases

GPL license
Make MySQL a Better MySQL
Develop, Promote and Support MySQL
MySQL Community Edition
7
Oracle + MySQL Customers

Product Integration
- Oracle GoldenGate (Complete!)
- Oracle Enterprise Linux + Oracle VM
- Oracle Secure Backup
- Oracle Audit Vault
- Oracle Enterprise Manager

Support
- Leverage 24x7, World-Class Oracle Support
- MyOracle Support
8
MySQL Connectors

Connector/ODBC

Connector/J

Connector/Net

Connector/MXJ

Connector/C

Connector/C++

PHP drivers

Perl Driver

Python driver

Ruby driver

C++ wrapper for MySQL C API


Developed by MySQL Developed by Community
9
Filesystems, Files and Logs
Redo, Undo, Data, Index, Binary, Error, Query and Slow
Pluggable Storage Engines Architecture
Connectors
Native C API, JDBC, ODBC, .Net, PHP, Ruby, Python, Perl
Connection Pool
Authentication Thread Reuse Connection Limits Check Memory Caches
Enterprise Management Services and
Utilities
Backup & Recovery
Security
Replication
Cluster
Partitioning
Instance Manager
Information_Schema
MySQL Workbench
SQL Interface
DDL, DML, Stored Procedures,
Views, Triggers, Etc..
Parser
Query Translation, Object
Privileges
Optimizer
Access Paths, Statistics
Caches
Global and Engine Specific
Caches and Buffers
Pluggable Storage Engines
Memory, Index and Storage Management
InnoDB MyISAM Cluster Etc Partners Community More..
MySQL Server
Clients and Apps
10
Languages
- 57% of MySQL Enterprise Customers Develop Using Java
-73% of MySQL Community Customers Develop Using PHP
11
Connectors for Java

MySQL Connector/J is a MySQL-developed JDBC connector for Java


client applications

JDBC Type 4 driver

Connector/J with J2EE and Other Java Frameworks

GlassFish

Jboss

Spring

Tomcat
12
Connector/J
Connector/J 5.1 provides ease of development features
Per connection client information
Categorized SQLExceptions
Standardized validity checks
Connector/J 5.0 includes XA support
Connector/J 3.0 does not support server-side prepared statements,and does not support any
of the features in versions of MySQL later than 4.1
13
Basics of Connector/J

The JDBC URL format for MySQL Connector/J is as follows


jdbc:mysql://[host][:port]/[database] [?propertyName1][=propertyValue1]
[&propertyName2][=propertyValue2]...
If the host name is not specified, it defaults to 127.0.0.1. If the port is not
specified, it defaults to 3306, the default port number for MySQL servers.
14
Basics of Connector/J
USE database1;
SELECT COUNT(*) FROM table1; # selects from
database1.table1
USE database2;
SELECT COUNT(*) FROM table; # selects from
database2.table
Unlike Under MySQL Client
JDBC clients should never employ the USE database statement to specify the desired database,
they should always use the Connection.setCatalog() method instead.
15
Connector/J example
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Conn = DriverManager.getConnection("jdbc:mysql://localhost/test?" +"user=root&password=mysql");
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT foo FROM bar");
if (stmt.execute("SELECT foo FROM bar")) {
rs = stmt.getResultSet();
}
} catch (SQLException ex) {
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode()); }
16
Fail Over Support
MySQL Connector/J has fail-over support. This enables the driver to fail over to any number of slave
hosts and still perform read-only queries. Fail over only happens when the connection is in an
autoCommit(true) state, because fail-over can not happen reliably when a transaction is in progress.
The fail-over functionality has the following behavior:
If the URL property autoReconnect is false: Failover only happens at connection initialization,
and failback occurs when the driver determines that the first host has become available again.
If the URL property autoReconnect is true: Failover happens when the driver determines that the
connection has failed (before every query), and falls back to the first host when it determines that
the host has become available again
In either case, whenever you are connected to a "failed-over" server, the connection will be set to
read-only state, so queries that would modify data will have exceptions thrown.
17
Load Balancing/Failover Use Cases

Directly (jdbc:mysql:loadbalance:// host-1,host-2,...host


n/ database):

Clustered (NDB) deployment where both read and write


operations are distributed across all hosts.

Indirectly:

Replication deployments where read-only load can be


distributed to slaves (jdbc:mysql:replication://)
18
MySQL Cluster Data Nodes
MySQL Cluster Application Nodes
MySQL Cluster
Mgmt
Clients
MySQL Cluster
Mgmt
MySQL Cluster Architecture
19
props.put("autoReconnect", "true"); // We want this for failover on the slaves
props.put("roundRobinLoadBalance", "true"); // We want to load balance between the slaves
props.put("user", "foo");
props.put("password", "bar");
Connection conn=driver.connect("jdbc:mysql:replication://master,slave1,slave2,slave3/test", props);
conn.setReadOnly(false); // Perform read/write work on the master by setting the read-only flag to "false"
conn.setAutoCommit(false);
conn.createStatement().executeUpdate("UPDATE some_table ....");
conn.commit();
// Now, do a query from a slave, the driver automatically picks one from the list
conn.setReadOnly(true);
ResultSet rs =conn.createStatement().executeQuery("SELECT a,b FROM alt_table");

Read-only load distribution
20
MySQL Replication
Read Scalability
C
l
i
e
n
t
s
Slaves Master
MySQL Replication
Used by leading web properties for scale-out
Reads are directed to slaves, writes to master
Delivers higher performance & scale with efficient resource utilization
21
Dont Forget !
The "loadBalanceBlacklistTimeout" adds the needed feature that failed
connections in a connection pool are put aside for the specified time, and
only working connections are utilized.
Set loadBalanceBlacklistTimeout to your best case outage window (in
milliseconds)
jdbc:mysql:loadbalance://host-1,host-2,...host-n/database?loadBalanceBlacklistTimeout=5000
(setting it to zero means hosts wont be automatically blacklisted)
22
Connector MXJ

Connector/MXJ is a Java utility package for deploying and managing a


MySQL database.

Not an embedded version of MySQL

Not a version of MySQL written as part of a Java class

Works through the use of an embedded, compiled binary of mysqld

The same as deploying a standard MySQL installation


It is the Connector/MXJ wrapper, support classes and tools that enable
Connector/MXJ to appear as a MySQL instance
23
Internals of Connector/MXJ
24
MySQL- XML

You can retrieve data from MySQL in XML format, and store data obtained
from an XML source into the database.

Better XML handling through Xpath functions


ExtractValue() allows you to use an XPath expression on a fragment of XML in
order to return the content of one or more elements
UpdateXML() makes it possible to replace an existing XML fragment with a new
one, using XPath to specify the fragment to be replaced.
25
ExtractValue()
mysql> SELECT @xml\G
*************************** 1. row ***************************
@xml: <?xml version="1.0"?>
<resultset statement="SELECT name,country FROM cities
LIMIT 2
" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<row>
<field name="name">Mumbai (Bombay)</field>
<field name="country">India</field>
</row>
<row>
<field name="name">Seoul</field>
<field name="country">South Korea</field>
</row>
</resultset>
mysql> SELECT ExtractValue(@xml, '//row[2]/field[1]');
+-----------------------------------------+
| ExtractValue(@xml, '//row[2]/field[1]') |
+-----------------------------------------+
| Seoul |
+-----------------------------------------+
1 row in set (0.00 sec)
Another way-
mysql> SELECT ExtractValue(@xml, '//field[@name="name"][2]');
+------------------------------------------------+
| ExtractValue(@xml, '//field[@name="name"][2]') |
+------------------------------------------------+
| Seoul |
+------------------------------------------------+
1 row in set (0.00 sec)
26
UpdateXML()
mysql> SELECT
@new_xml:=UpdateXML('<book><chapter/></book>',
-> '//chapter',
-> '<part><chapter/></part>')
-> AS uxml;
+--------------------------------------------------------------------+
| uxml |
+--------------------------------------------------------------------+
| <book><part><chapter/></part></book> |
+--------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT @new_xml;
+--------------------------------------+
| @new_xml |
+--------------------------------------+
| <book><part><chapter/></part></book> |
+--------------------------------------+
1 row in set (0.00 sec)
Consider the XML fragment <book><chapter/></book>. Now suppose you wish to change this to
<book><part><chapter/></part></book>. This shows how you can do so using UpdateXML(), saving the result into a user
variable @new_xml:
27
InnoDB becomes default storage engine
ACID Transactions, FKs, Crash Recovery
Improved Performance
Scales upto 32 cores
Improved Recovery time
+ 360% over 5.1 on Linux
+ 1500% over 5.1 on Windows
Improved Availability
Semi-synchronous Replication
Replication Heartbeat
Improved Usability
SIGNAL/RESIGNAL
More Partitioning Options
New PERFORMANCE_SCHEMA
MySQL 5.5 Highest Quality Release Ever
GA
28
MySQL 5.5 Scales on multi core
SysBench Read Write
GA
AMD Opteron 7160 (Magny-Cours) @2100 MHz
64 GB memory
2 x Intel X25E SSD drives
OS is Oracle Enterprise Linux with the
Enterprise Kernel
4 sockets with a total of 48 cores.
MySQL 5.5 SysBench Benchmarks
Windows
MySQL 5.1.50
(InnoDB built-in)
MySQL 5.1.50
(InnoDB Plug-in)
MySQL 5.5.6
(New InnoDB)
Intel x86_64
4 CPU x 2 Cores/CPU
3.166 GHz, 8GB RAM
Windows Server 2008
1561% performance gain
for MySQL 5.5 over 5.1.50; at scale
GA
30
MySQL Product Releases
Continuous Innovation
Q1 CY2010 Q2 CY2010 Q3 CY2010 Q4 CY2010
MySQL Enterprise Monitor 2.2
GA
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 now!
MySQL Cluster 7.1
GA
A Better MySQL
MySQL Cluster Manager 1.0
GA
31
New Packaging and Pricing
32
Comprehensive offering of MySQL Database, Management tools, and Oracle
Lifetime Support services
Database
MySQL Enterprise Monitor
Performance Monitoring/ Alerts
Hot fixes
Service packs
MySQL Workbench
Oracle Lifetime Support
MySQL Enterprise Backup
MySQL Enterprise Edition
Query Analyzer
Management Support
33
MySQL Enterprise Monitor
Single,consolidated view into entire MySQL
application development environment
Auto-discovery of MySQL servers, replication topologies
Automated, customizable rules-based monitoring,
tuning, SNMP/SMTP alerts
Query Analyzer for query monitoring, analysis, tuning,
source code tracing
Application Tuning during Dev/QA/Roll out
Reduces risk of problems after apps are deployed
A Virtual MySQL Tuning Assistant!
34
Monitoring Queries with Connector/J, NET
1. MySQL Enterprise Monitor & Query Analyzer (2.2)
2. MySQL Agent (2.2)
3. Connector/J v5.1 or newer/ Connector/NET v6.2 or newer
4. New! MySQL Enterprise Plugin for Connector/J, NET
List of components to download & configure:
MySQL Database
(MySQL & OS
monitoring data)
3. Connector/J, NET
4. Plugin for Connector/J, NET
(SQL performance data: statements,
examples, EXPLAINs, aggregated stats)
3306
18080
2. MySQL Agent
1. MySQL Enterprise Monitor
(Service Manager, Dashboard)
Application Server
(Sql statements and result sets)
35
MySQL Enterprise Backup
! Formerly InnoDB Hot Backup
! InnoDB Hot Backup is rebranded as MySQL Enterprise Backup

Online, non-locking backup & recovery


- Tables, Indexes
- Server, database

Incremental backup

Point-in-time recovery

Compressed backups

Also provides backup & recovery for MyISAM

Cross-Platform (Windows, Linux, Unix)


36
High Performance Backups
Backups are up to 3.5x Faster than mysqldump
GA
37
High Performance Restore
Restore is up to 16x Faster than mysqldump
GA
38
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 Oracles products remains
at the sole discretion of Oracle.
39

- Crash-Safe Slaves
- Multi-threaded Slaves
- Replication Checksums
- Time-Delayed Replication
- Remote Binlog Backups
dev.mysql.com/downloads/mysql
MySQL 5.6 A Better MySQL
DM
Download!
Better Replication
- Persistent Optimizer Stats
- New INFORMATION_SCHEMA tables:
Better InnoDB
40
MySQL 5.6:
NotOnlySQL: Memcached API
DM
Download!
InnoDB Storage Engine
MySQL
Server
Memcached
plugin
Application
SQL
(MySQL Client)
NoSQL (Memcached
Protocol)
mysqld
Fast, simple access to InnoDB
Accessed via Memcached API
Use existing Memcached clients
Bypasses SQL transformations
NotOnlySQL access
Memcached for key-value operations
SQL for rich queries, JOINs, foreign keys, etc.
Implementation
Memcached daemon plug-in to mysqld
Memcached protocol mapped to the native
InnoDB API
Shared process space for ultra-low latency
Additional implementations in future DMs
41
Useful Links
Connector J
http://dev.mysql.com/downloads/connector/j/
MySQL Replication Whitepaper
http://www.mysql.com/why-mysql/white-papers/mysql-wp-replication.php
MySQL On-Demand Webinars
http://www.mysql.com/news-and-events/on-demand-webinars/
MySQL Enterprise Whitepaper
http://www.mysql.com/why-mysql/white-papers/mysql_wp_enterprise_ready.php
42
Need to contact ????
Chandra Balani
MySQL Country Sales Manager
Mobile: +91.9000302255
Office: +914066581726
Email: Chandra.Balani@oracle.com
Ronen Baram
MySQL Senior Sales Consultant
Mobile: +61 400 77 35 44
Email: Ronen.Baram@oracle.com
43
44
45
Java Technology

Java technology is both a programming language and a platform

Open source

The Java platform is ubiquitous:


More than 6.5 million developers
In every major industry segment
In wide range of devices, computers, and networks

Java is
Simple
Architecture neutral
Object oriented and Portable
Distributed and High performance
Multithreaded and Robust
Dynamic & Secure
46
Why Java & MySQL

Open source and community driven

Ease of use

Ubiquity

MySQLs high performance combined with powerful Java


Servlet technology creates secure, robust, reliable, online
applications.

Easy to embed a full blown MySQL server (mysqld) into your


Java applications
47
Java - XML

Java revolutionized the programming world by providing a platform-


independent programming language.

XML takes the revolution a step further with a platform-independent


language for interchanging data.
Java and XML share many features that are ideal for building web-based enterprise
applications, such as platform-independence, extensibility, reusability, and global
language (Unicode) support, and both are based on industry standards.

You might also like