SlideShare a Scribd company logo
1 of 35
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

What's hot

MySQL Performance Schema in Action
MySQL Performance Schema in ActionMySQL Performance Schema in Action
MySQL Performance Schema in ActionSveta Smirnova
 
MariaDB Optimizer
MariaDB OptimizerMariaDB Optimizer
MariaDB OptimizerJongJin Lee
 
Developers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sad
Developers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sadDevelopers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sad
Developers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sadmCloud
 
15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performance15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performanceguest9912e5
 
Parallel Query in AWS Aurora MySQL
Parallel Query in AWS Aurora MySQLParallel Query in AWS Aurora MySQL
Parallel Query in AWS Aurora MySQLMydbops
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slidesmetsarin
 
Capturing, Analyzing, and Optimizing your SQL
Capturing, Analyzing, and Optimizing your SQLCapturing, Analyzing, and Optimizing your SQL
Capturing, Analyzing, and Optimizing your SQLPadraig O'Sullivan
 
Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesAjax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesDoris Chen
 
JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0Mydbops
 
Memcached Presentation @757rb
Memcached Presentation @757rbMemcached Presentation @757rb
Memcached Presentation @757rbKen Collins
 
Performance Schema for MySQL troubleshooting
Performance Schema for MySQL troubleshootingPerformance Schema for MySQL troubleshooting
Performance Schema for MySQL troubleshootingSveta Smirnova
 
Database Connection With Mysql
Database Connection With MysqlDatabase Connection With Mysql
Database Connection With MysqlHarit Kothari
 
Introducing new SQL syntax and improving performance with preparse Query Rewr...
Introducing new SQL syntax and improving performance with preparse Query Rewr...Introducing new SQL syntax and improving performance with preparse Query Rewr...
Introducing new SQL syntax and improving performance with preparse Query Rewr...Sveta Smirnova
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
Memcached Functions For My Sql Seemless Caching In My Sql
Memcached Functions For My Sql Seemless Caching In My SqlMemcached Functions For My Sql Seemless Caching In My Sql
Memcached Functions For My Sql Seemless Caching In My SqlMySQLConference
 

What's hot (20)

MySQL Performance Schema in Action
MySQL Performance Schema in ActionMySQL Performance Schema in Action
MySQL Performance Schema in Action
 
MariaDB Optimizer
MariaDB OptimizerMariaDB Optimizer
MariaDB Optimizer
 
Developers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sad
Developers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sadDevelopers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sad
Developers’ mDay 2021: Bogdan Kecman, Oracle – MySQL nekad i sad
 
15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performance15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performance
 
Parallel Query in AWS Aurora MySQL
Parallel Query in AWS Aurora MySQLParallel Query in AWS Aurora MySQL
Parallel Query in AWS Aurora MySQL
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
 
Capturing, Analyzing, and Optimizing your SQL
Capturing, Analyzing, and Optimizing your SQLCapturing, Analyzing, and Optimizing your SQL
Capturing, Analyzing, and Optimizing your SQL
 
Mysql all
Mysql allMysql all
Mysql all
 
My SQL 101
My SQL 101My SQL 101
My SQL 101
 
Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesAjax Performance Tuning and Best Practices
Ajax Performance Tuning and Best Practices
 
JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0
 
Memcached Presentation @757rb
Memcached Presentation @757rbMemcached Presentation @757rb
Memcached Presentation @757rb
 
MySQL
MySQLMySQL
MySQL
 
Performance Schema for MySQL troubleshooting
Performance Schema for MySQL troubleshootingPerformance Schema for MySQL troubleshooting
Performance Schema for MySQL troubleshooting
 
Database Connection With Mysql
Database Connection With MysqlDatabase Connection With Mysql
Database Connection With Mysql
 
Terraform Cosmos DB
Terraform Cosmos DBTerraform Cosmos DB
Terraform Cosmos DB
 
Introducing new SQL syntax and improving performance with preparse Query Rewr...
Introducing new SQL syntax and improving performance with preparse Query Rewr...Introducing new SQL syntax and improving performance with preparse Query Rewr...
Introducing new SQL syntax and improving performance with preparse Query Rewr...
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
Introduction Mysql
Introduction Mysql Introduction Mysql
Introduction Mysql
 
Memcached Functions For My Sql Seemless Caching In My Sql
Memcached Functions For My Sql Seemless Caching In My SqlMemcached Functions For My Sql Seemless Caching In My Sql
Memcached Functions For My Sql Seemless Caching In My Sql
 

Viewers also liked

JavaCro 2014 Digital Development with Java EE and Java Platform
JavaCro 2014 Digital Development with Java EE and Java PlatformJavaCro 2014 Digital Development with Java EE and Java Platform
JavaCro 2014 Digital Development with Java EE and Java PlatformPeter Pilgrim
 
Webinar: From Relational Databases to MongoDB - What You Need to Know
Webinar: From Relational Databases to MongoDB - What You Need to KnowWebinar: From Relational Databases to MongoDB - What You Need to Know
Webinar: From Relational Databases to MongoDB - What You Need to KnowMongoDB
 
Mysql index
Mysql indexMysql index
Mysql indexYuan Yao
 
2. writing MySql plugins general
2. writing MySql plugins   general2. writing MySql plugins   general
2. writing MySql plugins generalRoland Bouman
 
Optimizing mysql stored routines uc2010
Optimizing mysql stored routines uc2010Optimizing mysql stored routines uc2010
Optimizing mysql stored routines uc2010Roland Bouman
 

Viewers also liked (8)

JavaCro 2014 Digital Development with Java EE and Java Platform
JavaCro 2014 Digital Development with Java EE and Java PlatformJavaCro 2014 Digital Development with Java EE and Java Platform
JavaCro 2014 Digital Development with Java EE and Java Platform
 
Pdt tics
Pdt ticsPdt tics
Pdt tics
 
Webinar: From Relational Databases to MongoDB - What You Need to Know
Webinar: From Relational Databases to MongoDB - What You Need to KnowWebinar: From Relational Databases to MongoDB - What You Need to Know
Webinar: From Relational Databases to MongoDB - What You Need to Know
 
Mysql index
Mysql indexMysql index
Mysql index
 
2. writing MySql plugins general
2. writing MySql plugins   general2. writing MySql plugins   general
2. writing MySql plugins general
 
Optimizing mysql stored routines uc2010
Optimizing mysql stored routines uc2010Optimizing mysql stored routines uc2010
Optimizing mysql stored routines uc2010
 
MySQL database
MySQL databaseMySQL database
MySQL database
 
MySql slides (ppt)
MySql slides (ppt)MySql slides (ppt)
MySql slides (ppt)
 

Similar to Common schema my sql uc 2012

MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)Valeriy Kravchuk
 
Advanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and AnalysisAdvanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and AnalysisMYXPLAIN
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015Dave Stokes
 
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015Dave Stokes
 
DB Floripa - ProxySQL para MySQL
DB Floripa - ProxySQL para MySQLDB Floripa - ProxySQL para MySQL
DB Floripa - ProxySQL para MySQLMarcelo Altmann
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingSveta Smirnova
 
MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 MinutesSveta Smirnova
 
FOSDEM 2015: gdb tips and tricks for MySQL DBAs
FOSDEM 2015: gdb tips and tricks for MySQL DBAsFOSDEM 2015: gdb tips and tricks for MySQL DBAs
FOSDEM 2015: gdb tips and tricks for MySQL DBAsValerii Kravchuk
 
MySQL sys schema deep dive
MySQL sys schema deep diveMySQL sys schema deep dive
MySQL sys schema deep diveMark Leith
 
Performance schema and sys schema
Performance schema and sys schemaPerformance schema and sys schema
Performance schema and sys schemaMark Leith
 
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...Nelson Calero
 
Tracing and profiling my sql (percona live europe 2019) draft_1
Tracing and profiling my sql (percona live europe 2019) draft_1Tracing and profiling my sql (percona live europe 2019) draft_1
Tracing and profiling my sql (percona live europe 2019) draft_1Valerii Kravchuk
 
The MySQL SYS Schema
The MySQL SYS SchemaThe MySQL SYS Schema
The MySQL SYS SchemaMark Leith
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingSveta Smirnova
 
6 tips for improving ruby performance
6 tips for improving ruby performance6 tips for improving ruby performance
6 tips for improving ruby performanceEngine Yard
 

Similar to Common schema my sql uc 2012 (20)

MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
 
Mysql tracing
Mysql tracingMysql tracing
Mysql tracing
 
Mysql tracing
Mysql tracingMysql tracing
Mysql tracing
 
Advanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and AnalysisAdvanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and Analysis
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
 
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015
 
DB Floripa - ProxySQL para MySQL
DB Floripa - ProxySQL para MySQLDB Floripa - ProxySQL para MySQL
DB Floripa - ProxySQL para MySQL
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
 
MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 Minutes
 
FOSDEM 2015: gdb tips and tricks for MySQL DBAs
FOSDEM 2015: gdb tips and tricks for MySQL DBAsFOSDEM 2015: gdb tips and tricks for MySQL DBAs
FOSDEM 2015: gdb tips and tricks for MySQL DBAs
 
MySQL sys schema deep dive
MySQL sys schema deep diveMySQL sys schema deep dive
MySQL sys schema deep dive
 
Performance schema and sys schema
Performance schema and sys schemaPerformance schema and sys schema
Performance schema and sys schema
 
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
Evolution of Performance Management: Oracle 12c adaptive optimizations - ukou...
 
Tracing and profiling my sql (percona live europe 2019) draft_1
Tracing and profiling my sql (percona live europe 2019) draft_1Tracing and profiling my sql (percona live europe 2019) draft_1
Tracing and profiling my sql (percona live europe 2019) draft_1
 
The MySQL SYS Schema
The MySQL SYS SchemaThe MySQL SYS Schema
The MySQL SYS Schema
 
Tek tutorial
Tek tutorialTek tutorial
Tek tutorial
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
 
6 tips for improving ruby performance
6 tips for improving ruby performance6 tips for improving ruby performance
6 tips for improving ruby performance
 
DPC Tutorial
DPC TutorialDPC Tutorial
DPC Tutorial
 
MySQLinsanity
MySQLinsanityMySQLinsanity
MySQLinsanity
 

More from Roland Bouman

Beyond OData: Introducing the XML/A model for ui5
Beyond OData: Introducing the XML/A model for ui5Beyond OData: Introducing the XML/A model for ui5
Beyond OData: Introducing the XML/A model for ui5Roland Bouman
 
Moving and Transforming Data with Pentaho Data Integration 5.0 CE (aka Kettle)
Moving and Transforming Data with Pentaho Data Integration 5.0 CE (aka Kettle)Moving and Transforming Data with Pentaho Data Integration 5.0 CE (aka Kettle)
Moving and Transforming Data with Pentaho Data Integration 5.0 CE (aka Kettle)Roland Bouman
 
Writing MySQL User-defined Functions in JavaScript
Writing MySQL User-defined Functions in JavaScriptWriting MySQL User-defined Functions in JavaScript
Writing MySQL User-defined Functions in JavaScriptRoland Bouman
 
3. writing MySql plugins for the information schema
3. writing MySql plugins for the information schema3. writing MySql plugins for the information schema
3. writing MySql plugins for the information schemaRoland Bouman
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012Roland Bouman
 
Roland bouman modern_data_warehouse_architectures_data_vault_and_anchor_model...
Roland bouman modern_data_warehouse_architectures_data_vault_and_anchor_model...Roland bouman modern_data_warehouse_architectures_data_vault_and_anchor_model...
Roland bouman modern_data_warehouse_architectures_data_vault_and_anchor_model...Roland Bouman
 

More from Roland Bouman (10)

Beyond OData: Introducing the XML/A model for ui5
Beyond OData: Introducing the XML/A model for ui5Beyond OData: Introducing the XML/A model for ui5
Beyond OData: Introducing the XML/A model for ui5
 
Moving and Transforming Data with Pentaho Data Integration 5.0 CE (aka Kettle)
Moving and Transforming Data with Pentaho Data Integration 5.0 CE (aka Kettle)Moving and Transforming Data with Pentaho Data Integration 5.0 CE (aka Kettle)
Moving and Transforming Data with Pentaho Data Integration 5.0 CE (aka Kettle)
 
Xmla4js
Xmla4jsXmla4js
Xmla4js
 
Xml4js pentaho
Xml4js pentahoXml4js pentaho
Xml4js pentaho
 
Writing MySQL User-defined Functions in JavaScript
Writing MySQL User-defined Functions in JavaScriptWriting MySQL User-defined Functions in JavaScript
Writing MySQL User-defined Functions in JavaScript
 
3. writing MySql plugins for the information schema
3. writing MySql plugins for the information schema3. writing MySql plugins for the information schema
3. writing MySql plugins for the information schema
 
1. MySql plugins
1. MySql plugins1. MySql plugins
1. MySql plugins
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
Writing MySQL UDFs
Writing MySQL UDFsWriting MySQL UDFs
Writing MySQL UDFs
 
Roland bouman modern_data_warehouse_architectures_data_vault_and_anchor_model...
Roland bouman modern_data_warehouse_architectures_data_vault_and_anchor_model...Roland bouman modern_data_warehouse_architectures_data_vault_and_anchor_model...
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/