SlideShare a Scribd company logo
Common Schema




                 A Framework for
             MySQL Server Administration




2012-04-12      http://code.google.com/p/common-schema/
Welcome!

Shlomi Noach
http://code.openark.org/blog/shlomi-noach
Common Schema founder


Roland Bouman
http://rpbouman.blogspot.com/
@rolandbouman
Common Schema Contributor
2012-04-12    http://code.google.com/p/common-schema/
Agenda

●   What's common_schema?
●   Installation
●   Monitoring
●   Security
●   Schema & Query Object Analysis
●   Function library
●   Scripting
●   How to contribute
2012-04-12         http://code.google.com/p/common-schema/
What's common_schema?

●   MySQL DBA Toolkit
●   Self-contained database schema
     ●   Tables
     ●   Views
     ●   Stored Routines
●   MySQL >= 5.1
●   BSD Licensed


2012-04-12         http://code.google.com/p/common-schema/
Getting common_schema

●   Download
     ●   http://code.google.com/p/common-schema/downloads
●   Code: SQL Script
     ●   common_schema_mysql_51-r<nnn>.sql
     ●   common_schema_innodb_plugin-r<nnn>.sql
     ●   common_schema_percona_server-r<nnn>.sql
●   Documentation: HTML
     ●   common_schema_doc_r<nnn>.tar.gz

2012-04-12        http://code.google.com/p/common-schema/
Installing common_schema
mysql> source ~/Downloads/common_schema_innodb_plugin-r218.sql
Database changed

Query OK, 0 rows affected (0.10 sec)

Query OK, 0 rows affected (0.10 sec)

...

Query OK, 0 rows affected (0.10 sec)

+-----------------------------------------------------------+
| complete                                                  |
+-----------------------------------------------------------+
| Installation complete. Thank you for using common_schema! |
+-----------------------------------------------------------+
1 row in set (0.00 sec)
 2012-04-12        http://code.google.com/p/common-schema/
Installing common_schema
mysql> select attribute_name, substr(attribute_value, 1, 50)
    -> from   common_schema.metadata;

+-------------------------+----------------------------------------------------+
| attribute_name          | substr(attribute_value, 1, 50)                     |
+-------------------------+----------------------------------------------------+
| author                  | Shlomi Noach                                       |
| author_url              | http://code.openark.org/blog/shlomi-noach          |
| license                 |
Copyright (c) 2011 - 2012, Shlomi Noach
All right |
| license_type            | New BSD                                            |
| project_home            | http://code.google.com/p/common-schema/            |
| project_name            | common_schema                                      |
| project_repository      | https://common-schema.googlecode.com/svn/trunk/    |
| project_repository_type | svn                                                |
| revision                | 218                                                |
+-------------------------+----------------------------------------------------+
9 rows in set (0.01 sec)




  2012-04-12             http://code.google.com/p/common-schema/
Built-in help
mysql> desc help_content;
+--------------+-------------+------+-----+---------+-------+
| Field        | Type        | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| topic        | varchar(32) | NO   | PRI | NULL    |       |
| help_message | text        | NO   |     | NULL    |       |
+--------------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> select topic from help_content;
+-----------------------------+
| topic                       |
+-----------------------------+
| auto_increment_columns      |
.                             .
. ...                         .
.                             .
| variables                   |
+-----------------------------+
107 rows in set (0.00 sec)



  2012-04-12             http://code.google.com/p/common-schema/
Built-in help
mysql> select help_message from help_content where topic = 'help' G
*************************** 1. row ***************************
help_message:
NAME

help(): search and read common_schema documentation.

TYPE

Procedure

DESCRIPTION

help() is a meta routine allowing access to documentation from within
common_schema itself.
The documentation, including, for example, this very page, is embedded within
common_schema's tables, such that it can be searched and read using standard
SQL queries.
help() accepts a search term, and presents a single documentation page which
best fits the term. The term may appear within the documentation's title or
description. It could be the name or part of name of one of common_schema's
components (routines, views, ...), or it could be any keyword appearing within
the documentation.
The output is MySQL-friendly, in that it breaks the documentation into rows of
text, thereby presenting the result in a nicely formatted table.


   2012-04-12               http://code.google.com/p/common-schema/
Monitoring

●   Status variables
     ●   global_status_diff
     ●   global_status_diff_nonzero
●   Transactions and locks
     ●   innodb_locked_transactions, innodb_simple_locks
     ●   innodb_transactions, innodb_transactions_summary
●   Processlist
     ●   processlist_grantees, processlist_per_userhost
     ●   processlist_summary, processlist_top
2012-04-12        http://code.google.com/p/common-schema/
Monitoring Status Variables
mysql> select variable_name           name,
    ->        variable_value_0        prev,
    ->        variable_value_1        curr,
    ->        variable_value_diff     diff,
    ->        variable_value_psec     psec,
    ->        variable_value_pminute pmin
    -> from   global_status_diff_nonzero;
+-----------------------+---------+---------+------+------+------+
| name                  | prev    | curr    | diff | psec | pmin |
+-----------------------+---------+---------+------+------+------+
| handler_read_rnd_next | 1276830 | 1277453 | 623 | 62.3 | 3738 |
| handler_write         | 79880   | 80812   | 932 | 93.2 | 5592 |
| open_files            | 37      | 35      |   -2 | -0.2 | -12 |
| qcache_not_cached     | 2303    | 2304    |    1 | 0.1 |     6 |
| select_full_join      | 33      | 34      |    1 | 0.1 |     6 |
| select_scan           | 2593    | 2595    |    2 | 0.2 |    12 |
+-----------------------+---------+---------+------+------+------+
6 rows in set, 4 warnings (10.03 sec)

  2012-04-12         http://code.google.com/p/common-schema/
Monitoring Processlist
mysql> select * from processlist_summary G
*************************** 1. row ***************************
        count_processes: 1
       active_processes: 0
     sleeping_processes: 1
         active_queries: 0
 num_queries_over_1_sec: 0
num_queries_over_10_sec: 0
num_queries_over_60_sec: 0
    average_active_time: 0.0000
1 row in set (0.00 sec)

mysql> select * from processlist_per_userhost G
*************************** 1. row ***************************
               user: root
               host: localhost
    count_processes: 1
   active_processes: 0
average_active_time: NULL
1 row in set (0.00 sec)
  2012-04-12          http://code.google.com/p/common-schema/
Security

●   Grants
     ●   sql_grants
     ●   sql_show_grants




2012-04-12       http://code.google.com/p/common-schema/
Object Analysis:
             Schema and Storage Engine
●   Data Size
     ●   data_size_per_engine
     ●   data_size_per_schema




2012-04-12        http://code.google.com/p/common-schema/
Object Analysis:
                       Data Size per Engine
mysql> select engine,
    ->        count_tables tabs,
    ->        data_size,
    ->        index_size,
    ->        total_size,
    ->        largest_table,
    ->        largest_table_size largest_size
    -> from   data_size_per_engine;
+--------+------+------------+------------+------------+-------------------------+--------------+
| engine | tabs | data_size | index_size | total_size | largest_table            | largest_size |
+--------+------+------------+------------+------------+-------------------------+--------------+
| CSV    |    2 |          0 |          0 |          0 | `mysql`.`slow_log`      |            0 |
| InnoDB |   80 |   39354368 |    5734400 |   45088768 | `hibernate`.`PRO_FILES` |     19398656 |
| MyISAM |   66 | 4767659576 | 2226202624 | 6993862200 | `pgn`.`t_ply`           |   4862971088 |
+--------+------+------------+------------+------------+-------------------------+--------------+
3 rows in set (0.17 sec)




   2012-04-12                  http://code.google.com/p/common-schema/
Object Analysis:
               Data Size per Schema
mysql> select *
    -> from   data_size_per_schema
    -> where table_schema = 'sakila' G
*************************** 1. row ***************************
      TABLE_SCHEMA: sakila
      count_tables: 16
       count_views: 7
  distinct_engines: 2
         data_size: 4297536
        index_size: 2647040
        total_size: 6944576
     largest_table: rental
largest_table_size: 2850816
1 row in set (0.14 sec)




  2012-04-12        http://code.google.com/p/common-schema/
Schema Object Analysis: Tables

●   DDL scripts
     ●   sql_alter_table
     ●   sql_foreign_keys




2012-04-12        http://code.google.com/p/common-schema/
Schema Object Analysis: Tables
mysql> select alter_statement
    -> from   common_schema.sql_alter_table
    -> where table_schema = 'sakila';
+-----------------------------------------------------+
| alter_statement                                     |
+-----------------------------------------------------+
| ALTER TABLE `sakila`.`actor` ENGINE=InnoDB          |
| ALTER TABLE `sakila`.`address` ENGINE=InnoDB        |
| ALTER TABLE `sakila`.`category` ENGINE=InnoDB       |
| ALTER TABLE `sakila`.`city` ENGINE=InnoDB           |
| ALTER TABLE `sakila`.`country` ENGINE=InnoDB        |
| ALTER TABLE `sakila`.`customer` ENGINE=InnoDB       |
| ALTER TABLE `sakila`.`film` ENGINE=InnoDB           |
| ALTER TABLE `sakila`.`film_actor` ENGINE=InnoDB     |
| ALTER TABLE `sakila`.`film_category` ENGINE=InnoDB |
| ALTER TABLE `sakila`.`film_text` ENGINE=MyISAM      |
| ALTER TABLE `sakila`.`inventory` ENGINE=InnoDB      |
| ALTER TABLE `sakila`.`language` ENGINE=InnoDB       |
| ALTER TABLE `sakila`.`payment` ENGINE=InnoDB        |
| ALTER TABLE `sakila`.`rental` ENGINE=InnoDB         |
| ALTER TABLE `sakila`.`staff` ENGINE=InnoDB          |
| ALTER TABLE `sakila`.`store` ENGINE=InnoDB          |
+-----------------------------------------------------+
16 rows in set (0.00 sec)

  2012-04-12              http://code.google.com/p/common-schema/
Schema Object Analysis: Tables
mysql> select alter_statement
    -> from   common_schema.sql_alter_table
    -> where table_schema = 'sakila';
+-----------------------------------------------------+
| alter_statement                                     |
+-----------------------------------------------------+
| ALTER TABLE `sakila`.`actor` ENGINE=InnoDB          |
| ALTER TABLE `sakila`.`address` ENGINE=InnoDB        |
| ALTER TABLE `sakila`.`category` ENGINE=InnoDB       |
| ALTER TABLE `sakila`.`city` ENGINE=InnoDB           |
| ALTER TABLE `sakila`.`country` ENGINE=InnoDB        |
| ALTER TABLE `sakila`.`customer` ENGINE=InnoDB       |
| ALTER TABLE `sakila`.`film` ENGINE=InnoDB           |
| ALTER TABLE `sakila`.`film_actor` ENGINE=InnoDB     |
| ALTER TABLE `sakila`.`film_category` ENGINE=InnoDB |
| ALTER TABLE `sakila`.`film_text` ENGINE=MyISAM      |
| ALTER TABLE `sakila`.`inventory` ENGINE=InnoDB      |
| ALTER TABLE `sakila`.`language` ENGINE=InnoDB       |
| ALTER TABLE `sakila`.`payment` ENGINE=InnoDB        |
| ALTER TABLE `sakila`.`rental` ENGINE=InnoDB         |
| ALTER TABLE `sakila`.`staff` ENGINE=InnoDB          |
| ALTER TABLE `sakila`.`store` ENGINE=InnoDB          |
+-----------------------------------------------------+
16 rows in set (0.00 sec)

  2012-04-12              http://code.google.com/p/common-schema/
Schema Object Analysis: Columns

●   Column overviews
     ●   auto_increment_columns
     ●   text_columns




2012-04-12       http://code.google.com/p/common-schema/
Schema Object Analysis:
                Auto Increment Columns
mysql> select table_name,
    ->        column_name,
    ->        data_type,
    ->        max_value,
    ->        auto_increment value,
    ->        auto_increment_ratio ratio
    -> from   auto_increment_columns
    -> where table_schema = 'sakila';
+------------+--------------+-----------+------------+-------+--------+
| TABLE_NAME | COLUMN_NAME | DATA_TYPE | max_value | value | ratio |
+------------+--------------+-----------+------------+-------+--------+
| actor      | actor_id     | smallint |       65535 |   201 | 0.0031 |
| address    | address_id   | smallint |       65535 |   606 | 0.0092 |
| category   | category_id | tinyint    |        255 |    17 | 0.0667 |
| city       | city_id      | smallint |       65535 |   601 | 0.0092 |
| country    | country_id   | smallint |       65535 |   110 | 0.0017 |
| customer   | customer_id | smallint |        65535 |   600 | 0.0092 |
| film       | film_id      | smallint |       65535 | 1001 | 0.0153 |
| inventory | inventory_id | mediumint |    16777215 | 4582 | 0.0003 |
| language   | language_id | tinyint    |        255 |     7 | 0.0275 |
| payment    | payment_id   | smallint |       65535 | 16050 | 0.2449 |
| rental     | rental_id    | int       | 2147483647 | 16050 | 0.0000 |
| staff      | staff_id     | tinyint   |        255 |     3 | 0.0118 |
| store      | store_id     | tinyint   |        255 |     3 | 0.0118 |
+------------+--------------+-----------+------------+-------+--------+
13 rows in set (0.08 sec)

   2012-04-12               http://code.google.com/p/common-schema/
Schema Object Analysis: Indexes

●   Keys and Indexes
     ●   candidate_keys
     ●   candidate_keys_recommended
     ●   no_pk_innodb_tables
     ●   rendundant_keys




2012-04-12       http://code.google.com/p/common-schema/
Schema Object Analysis:
                 Dependencies
●   Dependency Routines
     ●   get_event_dependencies(schema, name)
     ●   get_routine_dependencies(schema, name)
     ●   get_view_dependencies(schema, name)
     ●   get_sql_dependencies(sql, schema)




2012-04-12       http://code.google.com/p/common-schema/
Schema Object Analysis:
                    Dependencies
mysql> call get_view_dependencies('sakila', 'actor_info');
+-------------+---------------+-------------+--------+
| schema_name | object_name   | object_type | action |
+-------------+---------------+-------------+--------+
| sakila      | actor         | table       | select |
| sakila      | category      | table       | select |
| sakila      | film          | table       | select |
| sakila      | film_actor    | table       | select |
| sakila      | film_category | table       | select |
+-------------+---------------+-------------+--------+
5 rows in set (0.15 sec)


mysql> call get_routine_dependencies('sakila', 'rewards_report');
+-------------+-------------+-------------+--------+
| schema_name | object_name | object_type | action |
+-------------+-------------+-------------+--------+
| sakila      | customer    | table       | select |
| sakila      | payment     | table       | select |
| sakila      | tmpCustomer | table       | create |
| sakila      | tmpCustomer | table       | drop   |
| sakila      | tmpCustomer | table       | insert |
| sakila      | tmpCustomer | table       | select |
+-------------+-------------+-------------+--------+
6 rows in set (0.15 sec)


   2012-04-12               http://code.google.com/p/common-schema/
Function Library

●   Date/Time
     ●   start_of_() (hour, month, quarter, week, year)
     ●   easter_day()
●   Text
     ●   get_num_tokens(text, delim)
     ●   split_token()
●   Dynamic SQL
     ●   exec(), exec_file(), exec_single()

2012-04-12         http://code.google.com/p/common-schema/
Function Library: Date/Time
mysql> select now(),
    ->         start_of_hour(now()),
    ->         start_of_week(now()),
    ->         start_of_week_sunday(now()),
    ->         start_of_month(now()),
    ->         start_of_quarter(now()),
    ->         start_of_year(now()),
    ->         easter_day(now())
    -> G
*************************** 1. row ***************************
                       now(): 2012-04-12 10:55:55
        start_of_hour(now()): 2012-04-12 10:00:00
        start_of_week(now()): 2012-04-09
start_of_week_sunday(now()): 2012-04-08
       start_of_month(now()): 2012-04-01
    start_of_quarter(now()): 2012-04-01
        start_of_year(now()): 2012-01-01
           easter_day(now()): 2012-04-08
1 row in set (0.00 sec)




   2012-04-12               http://code.google.com/p/common-schema/
Scripting

●   General
     ●   eval(sql)
     ●   repeat_exec(interval, sql, condition)
     ●   foreach(collection, script)
     ●   $(collection, script)




2012-04-12       http://code.google.com/p/common-schema/
Scripting: eval()
mysql> call eval('
    '>   select concat(
    '>               'create table test.', table_name,
    '>               ' as select * from sakila.', table_name
    '>           )
    '>   from    information_schema.tables
    '>   where   table_schema = 'sakila'
    '> ');
Query OK, 0 rows affected (3.32 sec)

mysql> show tables in test;
+----------------------------+
| Tables_in_test             |
+----------------------------+
| actor                      |
. ...                        .
| store                      |
+----------------------------+
23 rows in set (0.00 sec)

mysql> call eval('
    '>   select concat('drop table test.', table_name)
    '>   from    information_schema.tables
    '>   where   table_schema = 'test'
    '> ');
Query OK, 0 rows affected (1.41 sec)

mysql> show tables in test;
Empty set (0.00 sec)
   2012-04-12                    http://code.google.com/p/common-schema/
Scripting:
                 foreach(range, script)
mysql> call $('1:3', 'select '${1}'');
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.19 sec)

+---+
| 2 |
+---+
| 2 |
+---+
1 row in set (0.34 sec)

+---+
| 3 |
+---+
| 3 |
+---+
1 row in set (0.50 sec)

  2012-04-12              http://code.google.com/p/common-schema/
Scripting:
                foreach(multi-range, script)
mysql> call $('1:2,5:6', 'select '${1}', '${2}'');
+---+---+
| 1 | 5 |
+---+---+
| 1 | 5 |
+---+---+
1 row in set (0.20 sec)

+---+---+
| 1 | 6 |
+---+---+
| 1 | 6 |
+---+---+
1 row in set (0.39 sec)

+---+---+
| 2 | 5 |
+---+---+
| 2 | 5 |
+---+---+
1 row in set (0.57 sec)

+---+---+
| 2 | 6 |
+---+---+
| 2 | 6 |
+---+---+
1 row in set (0.73 sec)

   2012-04-12                  http://code.google.com/p/common-schema/
Scripting:
                   foreach(select, script)
mysql> call $('select name from sakila.category', 'create table test.${1}(id int)');
mysql> show tables in test;
+----------------+
| Tables_in_test |
+----------------+
| Action         |
| Animation      |
| Children       |
| Classics       |
| Comedy         |
| Documentary    |
| Drama          |
| Family         |
| Foreign        |
| Games          |
| Horror         |
| Music          |
| New            |
| Sci-Fi         |
| Sports         |
| Travel         |
+----------------+
16 rows in set (0.01 sec)


  2012-04-12              http://code.google.com/p/common-schema/
Scripting:
       foreach(table in schema, script)
mysql> call common_schema.$('table in test', 'drop table test.`${1}`');
Query OK, 0 rows affected (0.18 sec)

mysql> show tables in test;
Empty set (0.00 sec)




  2012-04-12           http://code.google.com/p/common-schema/
Queryscript Language

●   Execute
     ●   run()
     ●   run_file()




2012-04-12       http://code.google.com/p/common-schema/
How to Contribute

●   Install and try it out
●   Blog about it
●   code.google.com/p/common-schema/issues/list




2012-04-12        http://code.google.com/p/common-schema/
Resources

●   code.google.com/p/common-schema
●   code.openark.org/blog/tag/common_schema




2012-04-12    http://code.google.com/p/common-schema/

More Related Content

PDF
MariaDB for developers
PPTX
My sql administration
PDF
New features in Performance Schema 5.7 in action
PDF
Highload Perf Tuning
PDF
Troubleshooting MySQL Performance
PDF
Perl Stored Procedures for MySQL (2009)
PDF
Modern query optimisation features in MySQL 8.
MariaDB for developers
My sql administration
New features in Performance Schema 5.7 in action
Highload Perf Tuning
Troubleshooting MySQL Performance
Perl Stored Procedures for MySQL (2009)
Modern query optimisation features in MySQL 8.

What's hot (20)

PDF
MySQL Performance Schema in Action
PDF
MariaDB Optimizer
PDF
Developers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sad
PPT
15 Ways to Kill Your Mysql Application Performance
PDF
Parallel Query in AWS Aurora MySQL
PPTX
PostgreSQL Database Slides
PDF
Capturing, Analyzing, and Optimizing your SQL
PDF
My SQL 101
PDF
Ajax Performance Tuning and Best Practices
PPTX
JSON improvements in MySQL 8.0
PDF
Memcached Presentation @757rb
PPT
PDF
Performance Schema for MySQL troubleshooting
ODP
Database Connection With Mysql
PDF
Terraform Cosmos DB
PDF
Introducing new SQL syntax and improving performance with preparse Query Rewr...
ODP
Caching and tuning fun for high scalability
PDF
Introduction Mysql
PDF
Memcached Functions For My Sql Seemless Caching In My Sql
MySQL Performance Schema in Action
MariaDB Optimizer
Developers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sad
15 Ways to Kill Your Mysql Application Performance
Parallel Query in AWS Aurora MySQL
PostgreSQL Database Slides
Capturing, Analyzing, and Optimizing your SQL
My SQL 101
Ajax Performance Tuning and Best Practices
JSON improvements in MySQL 8.0
Memcached Presentation @757rb
Performance Schema for MySQL troubleshooting
Database Connection With Mysql
Terraform Cosmos DB
Introducing new SQL syntax and improving performance with preparse Query Rewr...
Caching and tuning fun for high scalability
Introduction Mysql
Memcached Functions For My Sql Seemless Caching In My Sql
Ad

Viewers also liked (8)

PDF
JavaCro 2014 Digital Development with Java EE and Java Platform
PDF
Pdt tics
PPTX
Webinar: From Relational Databases to MongoDB - What You Need to Know
PDF
Mysql index
ODP
2. writing MySql plugins general
ODP
Optimizing mysql stored routines uc2010
PPTX
MySQL database
PPT
MySql slides (ppt)
JavaCro 2014 Digital Development with Java EE and Java Platform
Pdt tics
Webinar: From Relational Databases to MongoDB - What You Need to Know
Mysql index
2. writing MySql plugins general
Optimizing mysql stored routines uc2010
MySQL database
MySql slides (ppt)
Ad

Similar to Common schema my sql uc 2012 (20)

PDF
common_schema, DBA's framework for MySQL
PDF
common_schema 2.0: DBA's Framework for MySQL
KEY
Tek tutorial
PDF
common_schema 2.2: DBA's framework for MySQL (April 2014)
KEY
DPC Tutorial
PDF
Mysql Datadictionary
PDF
Copy Of Mysql Datadictionary
PDF
Mysql basics1
PDF
Introducción rápida a SQL
PDF
15 MySQL Basics #burningkeyboards
DOC
Using MySQL Meta Data Effectively
ODP
MySQL Scaling Presentation
DOCX
Performence tuning
PDF
Collaborate 2012 - Administering MySQL for Oracle DBAs
PDF
The MySQL SYS Schema
PPT
15 protips for mysql users pfz
PPT
Fudcon talk.ppt
PDF
PPT
mysqlHiep.ppt
PPT
MySQL Database System Hiep Dinh
common_schema, DBA's framework for MySQL
common_schema 2.0: DBA's Framework for MySQL
Tek tutorial
common_schema 2.2: DBA's framework for MySQL (April 2014)
DPC Tutorial
Mysql Datadictionary
Copy Of Mysql Datadictionary
Mysql basics1
Introducción rápida a SQL
15 MySQL Basics #burningkeyboards
Using MySQL Meta Data Effectively
MySQL Scaling Presentation
Performence tuning
Collaborate 2012 - Administering MySQL for Oracle DBAs
The MySQL SYS Schema
15 protips for mysql users pfz
Fudcon talk.ppt
mysqlHiep.ppt
MySQL Database System Hiep Dinh

More from Roland Bouman (10)

PPTX
Beyond OData: Introducing the XML/A model for ui5
ODP
Moving and Transforming Data with Pentaho Data Integration 5.0 CE (aka Kettle)
ODP
Xmla4js
ODP
Xml4js pentaho
PDF
Writing MySQL User-defined Functions in JavaScript
ODP
3. writing MySql plugins for the information schema
ODP
1. MySql plugins
ODP
Common schema my sql uc 2012
ODP
Writing MySQL UDFs
PDF
Roland bouman modern_data_warehouse_architectures_data_vault_and_anchor_model...
Beyond OData: Introducing the XML/A model for ui5
Moving and Transforming Data with Pentaho Data Integration 5.0 CE (aka Kettle)
Xmla4js
Xml4js pentaho
Writing MySQL User-defined Functions in JavaScript
3. writing MySql plugins for the information schema
1. MySql plugins
Common schema my sql uc 2012
Writing MySQL UDFs
Roland bouman modern_data_warehouse_architectures_data_vault_and_anchor_model...

Common schema my sql uc 2012

  • 1. Common Schema A Framework for MySQL Server Administration 2012-04-12 http://code.google.com/p/common-schema/
  • 2. Welcome! Shlomi Noach http://code.openark.org/blog/shlomi-noach Common Schema founder Roland Bouman http://rpbouman.blogspot.com/ @rolandbouman Common Schema Contributor 2012-04-12 http://code.google.com/p/common-schema/
  • 3. Agenda ● What's common_schema? ● Installation ● Monitoring ● Security ● Schema & Query Object Analysis ● Function library ● Scripting ● How to contribute 2012-04-12 http://code.google.com/p/common-schema/
  • 4. What's common_schema? ● MySQL DBA Toolkit ● Self-contained database schema ● Tables ● Views ● Stored Routines ● MySQL >= 5.1 ● BSD Licensed 2012-04-12 http://code.google.com/p/common-schema/
  • 5. Getting common_schema ● Download ● http://code.google.com/p/common-schema/downloads ● Code: SQL Script ● common_schema_mysql_51-r<nnn>.sql ● common_schema_innodb_plugin-r<nnn>.sql ● common_schema_percona_server-r<nnn>.sql ● Documentation: HTML ● common_schema_doc_r<nnn>.tar.gz 2012-04-12 http://code.google.com/p/common-schema/
  • 6. Installing common_schema mysql> source ~/Downloads/common_schema_innodb_plugin-r218.sql Database changed Query OK, 0 rows affected (0.10 sec) Query OK, 0 rows affected (0.10 sec) ... Query OK, 0 rows affected (0.10 sec) +-----------------------------------------------------------+ | complete | +-----------------------------------------------------------+ | Installation complete. Thank you for using common_schema! | +-----------------------------------------------------------+ 1 row in set (0.00 sec) 2012-04-12 http://code.google.com/p/common-schema/
  • 7. Installing common_schema mysql> select attribute_name, substr(attribute_value, 1, 50) -> from common_schema.metadata; +-------------------------+----------------------------------------------------+ | attribute_name | substr(attribute_value, 1, 50) | +-------------------------+----------------------------------------------------+ | author | Shlomi Noach | | author_url | http://code.openark.org/blog/shlomi-noach | | license | Copyright (c) 2011 - 2012, Shlomi Noach All right | | license_type | New BSD | | project_home | http://code.google.com/p/common-schema/ | | project_name | common_schema | | project_repository | https://common-schema.googlecode.com/svn/trunk/ | | project_repository_type | svn | | revision | 218 | +-------------------------+----------------------------------------------------+ 9 rows in set (0.01 sec) 2012-04-12 http://code.google.com/p/common-schema/
  • 8. Built-in help mysql> desc help_content; +--------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+-------------+------+-----+---------+-------+ | topic | varchar(32) | NO | PRI | NULL | | | help_message | text | NO | | NULL | | +--------------+-------------+------+-----+---------+-------+ 2 rows in set (0.00 sec) mysql> select topic from help_content; +-----------------------------+ | topic | +-----------------------------+ | auto_increment_columns | . . . ... . . . | variables | +-----------------------------+ 107 rows in set (0.00 sec) 2012-04-12 http://code.google.com/p/common-schema/
  • 9. Built-in help mysql> select help_message from help_content where topic = 'help' G *************************** 1. row *************************** help_message: NAME help(): search and read common_schema documentation. TYPE Procedure DESCRIPTION help() is a meta routine allowing access to documentation from within common_schema itself. The documentation, including, for example, this very page, is embedded within common_schema's tables, such that it can be searched and read using standard SQL queries. help() accepts a search term, and presents a single documentation page which best fits the term. The term may appear within the documentation's title or description. It could be the name or part of name of one of common_schema's components (routines, views, ...), or it could be any keyword appearing within the documentation. The output is MySQL-friendly, in that it breaks the documentation into rows of text, thereby presenting the result in a nicely formatted table. 2012-04-12 http://code.google.com/p/common-schema/
  • 10. Monitoring ● Status variables ● global_status_diff ● global_status_diff_nonzero ● Transactions and locks ● innodb_locked_transactions, innodb_simple_locks ● innodb_transactions, innodb_transactions_summary ● Processlist ● processlist_grantees, processlist_per_userhost ● processlist_summary, processlist_top 2012-04-12 http://code.google.com/p/common-schema/
  • 11. Monitoring Status Variables mysql> select variable_name name, -> variable_value_0 prev, -> variable_value_1 curr, -> variable_value_diff diff, -> variable_value_psec psec, -> variable_value_pminute pmin -> from global_status_diff_nonzero; +-----------------------+---------+---------+------+------+------+ | name | prev | curr | diff | psec | pmin | +-----------------------+---------+---------+------+------+------+ | handler_read_rnd_next | 1276830 | 1277453 | 623 | 62.3 | 3738 | | handler_write | 79880 | 80812 | 932 | 93.2 | 5592 | | open_files | 37 | 35 | -2 | -0.2 | -12 | | qcache_not_cached | 2303 | 2304 | 1 | 0.1 | 6 | | select_full_join | 33 | 34 | 1 | 0.1 | 6 | | select_scan | 2593 | 2595 | 2 | 0.2 | 12 | +-----------------------+---------+---------+------+------+------+ 6 rows in set, 4 warnings (10.03 sec) 2012-04-12 http://code.google.com/p/common-schema/
  • 12. Monitoring Processlist mysql> select * from processlist_summary G *************************** 1. row *************************** count_processes: 1 active_processes: 0 sleeping_processes: 1 active_queries: 0 num_queries_over_1_sec: 0 num_queries_over_10_sec: 0 num_queries_over_60_sec: 0 average_active_time: 0.0000 1 row in set (0.00 sec) mysql> select * from processlist_per_userhost G *************************** 1. row *************************** user: root host: localhost count_processes: 1 active_processes: 0 average_active_time: NULL 1 row in set (0.00 sec) 2012-04-12 http://code.google.com/p/common-schema/
  • 13. Security ● Grants ● sql_grants ● sql_show_grants 2012-04-12 http://code.google.com/p/common-schema/
  • 14. Object Analysis: Schema and Storage Engine ● Data Size ● data_size_per_engine ● data_size_per_schema 2012-04-12 http://code.google.com/p/common-schema/
  • 15. Object Analysis: Data Size per Engine mysql> select engine, -> count_tables tabs, -> data_size, -> index_size, -> total_size, -> largest_table, -> largest_table_size largest_size -> from data_size_per_engine; +--------+------+------------+------------+------------+-------------------------+--------------+ | engine | tabs | data_size | index_size | total_size | largest_table | largest_size | +--------+------+------------+------------+------------+-------------------------+--------------+ | CSV | 2 | 0 | 0 | 0 | `mysql`.`slow_log` | 0 | | InnoDB | 80 | 39354368 | 5734400 | 45088768 | `hibernate`.`PRO_FILES` | 19398656 | | MyISAM | 66 | 4767659576 | 2226202624 | 6993862200 | `pgn`.`t_ply` | 4862971088 | +--------+------+------------+------------+------------+-------------------------+--------------+ 3 rows in set (0.17 sec) 2012-04-12 http://code.google.com/p/common-schema/
  • 16. Object Analysis: Data Size per Schema mysql> select * -> from data_size_per_schema -> where table_schema = 'sakila' G *************************** 1. row *************************** TABLE_SCHEMA: sakila count_tables: 16 count_views: 7 distinct_engines: 2 data_size: 4297536 index_size: 2647040 total_size: 6944576 largest_table: rental largest_table_size: 2850816 1 row in set (0.14 sec) 2012-04-12 http://code.google.com/p/common-schema/
  • 17. Schema Object Analysis: Tables ● DDL scripts ● sql_alter_table ● sql_foreign_keys 2012-04-12 http://code.google.com/p/common-schema/
  • 18. Schema Object Analysis: Tables mysql> select alter_statement -> from common_schema.sql_alter_table -> where table_schema = 'sakila'; +-----------------------------------------------------+ | alter_statement | +-----------------------------------------------------+ | ALTER TABLE `sakila`.`actor` ENGINE=InnoDB | | ALTER TABLE `sakila`.`address` ENGINE=InnoDB | | ALTER TABLE `sakila`.`category` ENGINE=InnoDB | | ALTER TABLE `sakila`.`city` ENGINE=InnoDB | | ALTER TABLE `sakila`.`country` ENGINE=InnoDB | | ALTER TABLE `sakila`.`customer` ENGINE=InnoDB | | ALTER TABLE `sakila`.`film` ENGINE=InnoDB | | ALTER TABLE `sakila`.`film_actor` ENGINE=InnoDB | | ALTER TABLE `sakila`.`film_category` ENGINE=InnoDB | | ALTER TABLE `sakila`.`film_text` ENGINE=MyISAM | | ALTER TABLE `sakila`.`inventory` ENGINE=InnoDB | | ALTER TABLE `sakila`.`language` ENGINE=InnoDB | | ALTER TABLE `sakila`.`payment` ENGINE=InnoDB | | ALTER TABLE `sakila`.`rental` ENGINE=InnoDB | | ALTER TABLE `sakila`.`staff` ENGINE=InnoDB | | ALTER TABLE `sakila`.`store` ENGINE=InnoDB | +-----------------------------------------------------+ 16 rows in set (0.00 sec) 2012-04-12 http://code.google.com/p/common-schema/
  • 19. Schema Object Analysis: Tables mysql> select alter_statement -> from common_schema.sql_alter_table -> where table_schema = 'sakila'; +-----------------------------------------------------+ | alter_statement | +-----------------------------------------------------+ | ALTER TABLE `sakila`.`actor` ENGINE=InnoDB | | ALTER TABLE `sakila`.`address` ENGINE=InnoDB | | ALTER TABLE `sakila`.`category` ENGINE=InnoDB | | ALTER TABLE `sakila`.`city` ENGINE=InnoDB | | ALTER TABLE `sakila`.`country` ENGINE=InnoDB | | ALTER TABLE `sakila`.`customer` ENGINE=InnoDB | | ALTER TABLE `sakila`.`film` ENGINE=InnoDB | | ALTER TABLE `sakila`.`film_actor` ENGINE=InnoDB | | ALTER TABLE `sakila`.`film_category` ENGINE=InnoDB | | ALTER TABLE `sakila`.`film_text` ENGINE=MyISAM | | ALTER TABLE `sakila`.`inventory` ENGINE=InnoDB | | ALTER TABLE `sakila`.`language` ENGINE=InnoDB | | ALTER TABLE `sakila`.`payment` ENGINE=InnoDB | | ALTER TABLE `sakila`.`rental` ENGINE=InnoDB | | ALTER TABLE `sakila`.`staff` ENGINE=InnoDB | | ALTER TABLE `sakila`.`store` ENGINE=InnoDB | +-----------------------------------------------------+ 16 rows in set (0.00 sec) 2012-04-12 http://code.google.com/p/common-schema/
  • 20. Schema Object Analysis: Columns ● Column overviews ● auto_increment_columns ● text_columns 2012-04-12 http://code.google.com/p/common-schema/
  • 21. Schema Object Analysis: Auto Increment Columns mysql> select table_name, -> column_name, -> data_type, -> max_value, -> auto_increment value, -> auto_increment_ratio ratio -> from auto_increment_columns -> where table_schema = 'sakila'; +------------+--------------+-----------+------------+-------+--------+ | TABLE_NAME | COLUMN_NAME | DATA_TYPE | max_value | value | ratio | +------------+--------------+-----------+------------+-------+--------+ | actor | actor_id | smallint | 65535 | 201 | 0.0031 | | address | address_id | smallint | 65535 | 606 | 0.0092 | | category | category_id | tinyint | 255 | 17 | 0.0667 | | city | city_id | smallint | 65535 | 601 | 0.0092 | | country | country_id | smallint | 65535 | 110 | 0.0017 | | customer | customer_id | smallint | 65535 | 600 | 0.0092 | | film | film_id | smallint | 65535 | 1001 | 0.0153 | | inventory | inventory_id | mediumint | 16777215 | 4582 | 0.0003 | | language | language_id | tinyint | 255 | 7 | 0.0275 | | payment | payment_id | smallint | 65535 | 16050 | 0.2449 | | rental | rental_id | int | 2147483647 | 16050 | 0.0000 | | staff | staff_id | tinyint | 255 | 3 | 0.0118 | | store | store_id | tinyint | 255 | 3 | 0.0118 | +------------+--------------+-----------+------------+-------+--------+ 13 rows in set (0.08 sec) 2012-04-12 http://code.google.com/p/common-schema/
  • 22. Schema Object Analysis: Indexes ● Keys and Indexes ● candidate_keys ● candidate_keys_recommended ● no_pk_innodb_tables ● rendundant_keys 2012-04-12 http://code.google.com/p/common-schema/
  • 23. Schema Object Analysis: Dependencies ● Dependency Routines ● get_event_dependencies(schema, name) ● get_routine_dependencies(schema, name) ● get_view_dependencies(schema, name) ● get_sql_dependencies(sql, schema) 2012-04-12 http://code.google.com/p/common-schema/
  • 24. Schema Object Analysis: Dependencies mysql> call get_view_dependencies('sakila', 'actor_info'); +-------------+---------------+-------------+--------+ | schema_name | object_name | object_type | action | +-------------+---------------+-------------+--------+ | sakila | actor | table | select | | sakila | category | table | select | | sakila | film | table | select | | sakila | film_actor | table | select | | sakila | film_category | table | select | +-------------+---------------+-------------+--------+ 5 rows in set (0.15 sec) mysql> call get_routine_dependencies('sakila', 'rewards_report'); +-------------+-------------+-------------+--------+ | schema_name | object_name | object_type | action | +-------------+-------------+-------------+--------+ | sakila | customer | table | select | | sakila | payment | table | select | | sakila | tmpCustomer | table | create | | sakila | tmpCustomer | table | drop | | sakila | tmpCustomer | table | insert | | sakila | tmpCustomer | table | select | +-------------+-------------+-------------+--------+ 6 rows in set (0.15 sec) 2012-04-12 http://code.google.com/p/common-schema/
  • 25. Function Library ● Date/Time ● start_of_() (hour, month, quarter, week, year) ● easter_day() ● Text ● get_num_tokens(text, delim) ● split_token() ● Dynamic SQL ● exec(), exec_file(), exec_single() 2012-04-12 http://code.google.com/p/common-schema/
  • 26. Function Library: Date/Time mysql> select now(), -> start_of_hour(now()), -> start_of_week(now()), -> start_of_week_sunday(now()), -> start_of_month(now()), -> start_of_quarter(now()), -> start_of_year(now()), -> easter_day(now()) -> G *************************** 1. row *************************** now(): 2012-04-12 10:55:55 start_of_hour(now()): 2012-04-12 10:00:00 start_of_week(now()): 2012-04-09 start_of_week_sunday(now()): 2012-04-08 start_of_month(now()): 2012-04-01 start_of_quarter(now()): 2012-04-01 start_of_year(now()): 2012-01-01 easter_day(now()): 2012-04-08 1 row in set (0.00 sec) 2012-04-12 http://code.google.com/p/common-schema/
  • 27. Scripting ● General ● eval(sql) ● repeat_exec(interval, sql, condition) ● foreach(collection, script) ● $(collection, script) 2012-04-12 http://code.google.com/p/common-schema/
  • 28. Scripting: eval() mysql> call eval(' '> select concat( '> 'create table test.', table_name, '> ' as select * from sakila.', table_name '> ) '> from information_schema.tables '> where table_schema = 'sakila' '> '); Query OK, 0 rows affected (3.32 sec) mysql> show tables in test; +----------------------------+ | Tables_in_test | +----------------------------+ | actor | . ... . | store | +----------------------------+ 23 rows in set (0.00 sec) mysql> call eval(' '> select concat('drop table test.', table_name) '> from information_schema.tables '> where table_schema = 'test' '> '); Query OK, 0 rows affected (1.41 sec) mysql> show tables in test; Empty set (0.00 sec) 2012-04-12 http://code.google.com/p/common-schema/
  • 29. Scripting: foreach(range, script) mysql> call $('1:3', 'select '${1}''); +---+ | 1 | +---+ | 1 | +---+ 1 row in set (0.19 sec) +---+ | 2 | +---+ | 2 | +---+ 1 row in set (0.34 sec) +---+ | 3 | +---+ | 3 | +---+ 1 row in set (0.50 sec) 2012-04-12 http://code.google.com/p/common-schema/
  • 30. Scripting: foreach(multi-range, script) mysql> call $('1:2,5:6', 'select '${1}', '${2}''); +---+---+ | 1 | 5 | +---+---+ | 1 | 5 | +---+---+ 1 row in set (0.20 sec) +---+---+ | 1 | 6 | +---+---+ | 1 | 6 | +---+---+ 1 row in set (0.39 sec) +---+---+ | 2 | 5 | +---+---+ | 2 | 5 | +---+---+ 1 row in set (0.57 sec) +---+---+ | 2 | 6 | +---+---+ | 2 | 6 | +---+---+ 1 row in set (0.73 sec) 2012-04-12 http://code.google.com/p/common-schema/
  • 31. Scripting: foreach(select, script) mysql> call $('select name from sakila.category', 'create table test.${1}(id int)'); mysql> show tables in test; +----------------+ | Tables_in_test | +----------------+ | Action | | Animation | | Children | | Classics | | Comedy | | Documentary | | Drama | | Family | | Foreign | | Games | | Horror | | Music | | New | | Sci-Fi | | Sports | | Travel | +----------------+ 16 rows in set (0.01 sec) 2012-04-12 http://code.google.com/p/common-schema/
  • 32. Scripting: foreach(table in schema, script) mysql> call common_schema.$('table in test', 'drop table test.`${1}`'); Query OK, 0 rows affected (0.18 sec) mysql> show tables in test; Empty set (0.00 sec) 2012-04-12 http://code.google.com/p/common-schema/
  • 33. Queryscript Language ● Execute ● run() ● run_file() 2012-04-12 http://code.google.com/p/common-schema/
  • 34. How to Contribute ● Install and try it out ● Blog about it ● code.google.com/p/common-schema/issues/list 2012-04-12 http://code.google.com/p/common-schema/
  • 35. Resources ● code.google.com/p/common-schema ● code.openark.org/blog/tag/common_schema 2012-04-12 http://code.google.com/p/common-schema/