杜修文
ivan.tu@oracle.com
http://dev.mysql.com/
2
Introduction
5
“The most important trend indicated by the study is OSS DBMS… MySQL version 5.0 was released last fall
and is the first release with full SQL compliance and the necessary functionality to support full applications.
Therefore, its surprising strength so soon after release shows the strong worldwide desire to begin to use
OSS DBMS systems. During the next several years, this DBMS will attract much attention and contend
seriously with the other DBMS engines for application platform choice.”
Gartner 2006
7
• Community Server
– Database server for open source developers
• Embedded Database
– Database server for OEMs/ISVs to bundle cost-effectively
• MySQL Cluster
– Fault tolerant database clustering architecture
• MySQL Administrator
– Administration console
rd
• 3 party client tools
– Navcat
– TOAD for MySQL
– phpAdmin
Introduction 1.2 MySQL Products
9
MySQL Drivers
• MySQL C API
– libmysql: C implementation of the MySQL Client/Server protocol
– Often wrapped to provide bindings for other languages
• MySQL Connector/ODBC
– ODBC database API on Windows and Linux (based on libmysql)
• MySQL Connector/J
– JDBC Driver (Pure Java implementation of the client protocol)
• MySQL Connector/Net
– ADO.NET access from the .NET (Pure .NET implementation of the client
protocol)
• MySQL Connector/PHP
– mysql,mysqli, and PDO extensions (usually based on libmysql)
– mysqlnd : PHP Native driver (not a PHP script), can replace libmysql in
mysqli and MYSQL_PDO
MySQL Services
• MySQL Training
– Comprehensive set of MySQL training courses
• MySQL Certification
– High quality certification for MySQL Developers and
Database Administrators
• MySQL Consulting
– Full range of consulting services from start-up to optimization
• MySQL Support
– Community
– Enterprise (and other levels of purchased support)
Installing MySQL
Installation on Solaris
Solaris download is about 60 MB from mysql.com
Installation:
groupadd mysql
useradd -g mysql mysql
pkgadd -d package_name.pkg
20
Status Files
• Server creates several status files
• Some in data directory, some not
• Records server process ID in PID file
– host_name.pid
– --pid-file=file_name
• mysqld –log-bin=<base-binlog-file-name>
• my.cnf
– log-bin=<base-binlog-file-name>
29
Log format
• Assigned in mysqld option
– binlog-format=mixed[5.1.12~5.1.28]|row|statement[~5.1.11,5.1.29~]
• Mixed format
– switching from statement to row under the following conditions:
• When a DML statement updates an NDBCLUSTER table.
• When a function contains UUID().
• When 2 or more tables with AUTO_INCREMENT columns are updated.
• When any INSERT DELAYED is executed.
• When the body of a view requires row-based replication, the statement
creating the view also uses it — ex: when the statement creating a view
uses the UUID() function.
• When a call to a UDF is involved.
• If a statement is logged by row and the client that executed the
statement has any temporary tables, logging by row is used for all
subsequent statements until all temporary tables in use by that client
are dropped.
30
mysqlbinlog utility
– MySQL Administrator
• Provides automation
• Minimal tracking and reporting
– Datafiles
#cp /usr/local/mysql/data/ibdata* /var/backup/
– configuration file
#cp /etc/mysql/my.cnf /var/backup/my.cnf
Data Recovery
• Recovers data that changed since the last backup
• General recovery procedure
1. Copy data directory
2. Recover database using the backup
3. Re-execute the changes in the binary log
• Example
mysqlbinlog --start-position=23456 binlog.000004
| mysql -uroot -p
Basic Architecture
Upgrading is always
A slave can be a newer possible
Master/Slaves MySQL
version with a different row
Versions Slave can have fewer or
structure
more columns than master
MySQL Replication
63
• Replication Threads
– IO_THREAD
– SQL_THREAD
• Replication Files
– Relay Log Set
– Control Information
Files
• master.info
– Relay Log Files
• Relay-log.info
CHANGE MASTER TO
• Specifics on how to connect to the master and
where to start replicating from
CHANGE MASTER TO
MASTER_HOST = 'host_name',
MASTER_USER = 'user_name',
MASTER_PASSWORD = 'password',
MASTER_PORT = port_num,
MASTER_LOG_FILE = 'master_log_name',
MASTER_LOG_POS = master_log_pos
Error Log
• Connecting to master
• Checking master version
• Registering slave on master
• Requesting binlog dump
• Waiting to reconnect after a failed binlog dump
request
• Reconnecting after a failed binlog dump
request
MySQL Replication
70
MySQL Replication
71
Advantages/Disadvantages
• Advantages
– Simple to set up
– Included as part of MySQL
– Stable- supported in MySQL for many years/versions
– Secure - SLAVES can connect to MASTER with SSL
– Ability to access multiple servers
• Disadvantages
– Potential loss of data due to asynchronous replication.
– Fail-over is handled manually by applications
– MASTER can become the bottleneck
– application load balancing
– No multi-source capabilities
MySQL Replication
73
• Different Hardware
– Master
• RAID 1+0
– Slaves
• RAID 5 or RAID 0
MySQL Enterprise
• MySQL Enterprise Server
• Monthly Rapid Updates
Server • Quarterly Service Packs
• Hot Fix Program
• Extended End-of-Life
Subscription Level
Value to Customer
Platinum
Gold +
Gold
Silver + • Higher SLA than Gold
• Performance
Silver • 24/7 Support Advisor
Basic + • Enterprise Server • Schema Advisor
Advanced • Partitioning Review
(Partitioning) • Optimizes/Tunes
Business Hour • Query Analyzer • Custom
Phone Support • Replication Monitor Queries
Enterprise Monitor • Replication Advisor • Database
Basic Proactive • Memory Usage Design
Notifications Advisor • Custom Code
2 Incidents via email Expert Advice • Rapid Problem
support Optimizes MySQL Resolution
Enterprise Server Pro Configuration • (Hot Fix builds)
(Transactions) settings
Ensures Ensures
Uptime/Reliability Recoverability
Regular Service Packs Tightens Security
Self-help Support Extends Support
80
$40,000
• Simplify
> No Counting
> No Compliance Issues
• Eliminate
> No proprietary RBBMS license
fees
81
效果 - 視覺化查 看
看 SQL 指令和系統負荷的關連,以節省找出
耗用資源多的查 詢的時間。
詢的時間。
83
錯誤警示
用途 - 協助您找出以前無從偵測到的失敗或傳回錯誤結果
的查 詢。
詢。
84
Query Analyzer
在線放入産品更新 / 警示,支持服務
用途 - 提供單一,基於網路的主控台以進行監控 MySQL
産品更新和追踪支持狀態。
86
連線放入産品支持問題警示
87
Advisor
Administration Advisor
現在可監看 :
• 未開啟 的 的 5.1 Event
Schedule
• 重啟 的的 MySQL
Server
89
Graph
銀級 :
• 連線 - 最大量
金級 :
• MyISAM Key Buffer 的使用
白金級 :
• Table Lock Wait 比例
• InnoDB Adaptive Hash Index
Memory
• InnoDB Adaptive Hash Index
Searches
• InnoDB Adaptive Hash Index
Usage
90
Support Services
Customer Individual
• 詳細的文件和指引 Servers
Datacenter
• 以在線 / 郵電 / 電話 w/Agent
的方式按步驟協助
支持 Master-Slave Replication
• 支持團隊提供遠程
安裝 / 設定服務 Repository