0
MySQL schema
maintenance



        Giuseppe Maxia
   MySQL Community Team Lead
                             This work is ...
about me - Giuseppe Maxia
          a.k.a. The Data Charmer
          MySQL Community Team Lead
          Long time MyS...
Schema what?

        In a relational database, the schema defines the tables,
        the fields in each table, and the rel...
tables




Thursday, 03 December 2009
tables


                                           table name

                                      column column column...
tables
        CREATE TABLE employees
        (
          ID INT NOT NULL,
          name VARCHAR(20), name
              ...
relationship
             departments                          employees

         ID                  INT              ID...
relationship
             departments                          employees

         ID                  INT              ID...
relationship
             departments                           employees

         ID                  INT               ...
relationship
            customer

     ID                 INT

  name            varchar (10)

                          ...
relationship
            customer

     ID                 INT

  name            varchar (10)

                          ...
relationship
            customer
                                                              many
     ID              ...
relationship
            customer
                                                              many
     ID              ...
Main actors

                   • Production
                   • Development
                   • Stage
                 ...
Production database




                   • You must have one
Thursday, 03 December 2009
Development database




                   • Where you create new things
Thursday, 03 December 2009
Test database




                   • Where you experiment crazy ideas
Thursday, 03 December 2009
Stage database




                   • Where you test before deploying to
                             production


Thurs...
Schema maintenance
                             actions

                   • Reverse engineering
                   • For...
Reverse Engineering




Thursday, 03 December 2009
Reverse Engineering


                                             DDL
                 dept_emp
                    depar...
Reverse Engineering


                                             DDL
                 dept_emp
                    depar...
Reverse Engineering


                                             DDL
                 dept_emp
                    depar...
Forward Engineering




Thursday, 03 December 2009
Forward Engineering




Thursday, 03 December 2009
Forward Engineering




Thursday, 03 December 2009
Forward Engineering


                                             DDL
                 dept_emp
                    depar...
Forward Engineering
                                                                        .
                            ...
Synchronization




Thursday, 03 December 2009
Synchronization




Thursday, 03 December 2009
Synchronization




Thursday, 03 December 2009
Synchronization




Thursday, 03 December 2009
Synchronization




Thursday, 03 December 2009
Synchronization




Thursday, 03 December 2009
Synchronization




Thursday, 03 December 2009
Synchronization




Thursday, 03 December 2009
Synchronization




Thursday, 03 December 2009
Synchronization




Thursday, 03 December 2009
Synchronization




Thursday, 03 December 2009
Synchronization




Thursday, 03 December 2009
Synchronization




Thursday, 03 December 2009
How it works

                                                       yes
      Development                              OK...
How else it works


      Development                                       Production



                                ...
What happens in
                               between

      Development
                              no




           ...
What happens in
                               between

      Development
                              no         What no...
What happens in
                               between

      Development
                              no         What no...
What happens in
                               between

      Development
                              no         What no...
Schema maintenance: how to




                             1. Poor man's way
Thursday, 03 December 2009
How poor is the poor man?
                             • only command line access
                             • No Perl, ...
How poor is the poor man?
                                   ELY   • only command line access
                            ...
How poor is the poor man?
                                   ELY   • only command line access
                            ...
How poor is the poor man?
                                   ELY   • only command line access
                            ...
so, the extremely poor
                        man's way ...
                                 HOST 1    HOST 2
           ...
so, the extremely poor
                        man's way ...
                                          HOST 1    HOST 2
  ...
so, the extremely poor
                        man's way ...
                                          HOST 1    HOST 2
  ...
so, the extremely poor
                        man's way ...
                                          HOST 1       HOST 2...
so, the extremely poor
                        man's way ...
                                          HOST 1       HOST 2...
the poor man's way ...
                                           HOST 1     HOST 2
                                      ...
the poor man's way ...
                                           HOST 1     HOST 2
                                      ...
not so poor man's way ...
                                     HOST 1    HOST 2
                                 Developme...
not so poor man's way ...
                                     HOST 1    HOST 2
                                 Developme...
The rich man



                               http://aquafold.com




Thursday, 03 December 2009
The rich man



                                  http://aquafold.com




                       WARNING: doesn't deal wit...
MySQL Workbench



                             http://wb.mysql.com

Thursday, 03 December 2009
MySQL Workbench



                             http://wb.mysql.com

Thursday, 03 December 2009
MySQL Workbench



                             http://wb.mysql.com

Thursday, 03 December 2009
Schema and model




Thursday, 03 December 2009
Schema and model


                                             DDL
                 dept_emp
                    departme...
Schema and model


                                             DDL
                 dept_emp
                    departme...
Physical schema


                                            implemented
                                         in a sp...
Physical schema

                                                       DDL
                              dept_emp
       ...
Conceptual model



                                       DBMS agnostic




Thursday, 03 December 2009
Conceptual model



                                       DBMS agnostic




Thursday, 03 December 2009
MySQL Workbench
                                  basics


Thursday, 03 December 2009
Creating tables (1)




Thursday, 03 December 2009
Creating tables (2)




Thursday, 03 December 2009
Creating tables (3)




Thursday, 03 December 2009
Creating tables (3)




Thursday, 03 December 2009
Creating tables (4)




Thursday, 03 December 2009
Creating tables (4)




Thursday, 03 December 2009
Creating tables (5)




Thursday, 03 December 2009
Creating tables (5)




Thursday, 03 December 2009
database connections(1)




Thursday, 03 December 2009
database connections(2)




Thursday, 03 December 2009
Reverse engineering in
                       the old world




Thursday, 03 December 2009
Reverse engineering in
                       the old world
   show create table departmentsG

   Create Table: CREATE TAB...
Reverse engineering in
                       the old world
   show create table departmentsG

   Create Table: CREATE TAB...
Reverse engineering (1)




Thursday, 03 December 2009
Reverse engineering (2)




Thursday, 03 December 2009
Reverse engineering (3)




Thursday, 03 December 2009
Reverse engineering (4)




Thursday, 03 December 2009
Reverse engineering (5)




Thursday, 03 December 2009
Reverse engineering (6)




Thursday, 03 December 2009
Reverse engineering (7)




Thursday, 03 December 2009
Reverse engineering (8)




Thursday, 03 December 2009
Reverse engineering (9)




Thursday, 03 December 2009
Reverse engineering (10)




Thursday, 03 December 2009
forward engineering in
                       the old world
  mysqldump --host=development       -B 
         --no-data cr...
Forward engineering (1)




Thursday, 03 December 2009
Forward engineering (2)




Thursday, 03 December 2009
Forward engineering (3)




Thursday, 03 December 2009
Forward engineering (4)




Thursday, 03 December 2009
synchronization in the
                          old world




Thursday, 03 December 2009
Synchronization (1)




Thursday, 03 December 2009
Synchronization (1)




Thursday, 03 December 2009
Synchronization (2)




Thursday, 03 December 2009
Synchronization (3)




Thursday, 03 December 2009
Synchronization (4)




Thursday, 03 December 2009
Synchronization (5)




Thursday, 03 December 2009
Synchronization (6)




Thursday, 03 December 2009
More goodies


                   • MySQL Workbench 5.2 (Beta) - live demo



Thursday, 03 December 2009
Thanks
                             Let's talk!



Thursday, 03 December 2009
Upcoming SlideShare
Loading in...5
×

MySQL Schema Maintenance

5,360

Published on

Schema maintenance is a hot topic for database administrators. Especially if they have to maintain schemas for development, staging, and production, the task could be difficult and confusing. Using MySQL Workbench, schema maintenance is greatly simplified, and the tasks of synchronizing schemas across servers become easy and manageable.

Published in: Technology
0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,360
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
154
Comments
0
Likes
8
Embeds 0
No embeds

No notes for slide

Transcript of "MySQL Schema Maintenance"

  1. 1. MySQL schema maintenance Giuseppe Maxia MySQL Community Team Lead This work is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported License. Thursday, 03 December 2009
  2. 2. about me - Giuseppe Maxia  a.k.a. The Data Charmer  MySQL Community Team Lead  Long time MySQL hacker  Formerly, database consultant, designer, coder.  A passion for QA  An even greater passion for open source  ... and community  Passionate blogger  http://datacharmer.blogspot.com Thursday, 03 December 2009
  3. 3. Schema what? In a relational database, the schema defines the tables, the fields in each table, and the relationships between fields and tables. http://en.wikipedia.org/wiki/Schema_(database) Thursday, 03 December 2009
  4. 4. tables Thursday, 03 December 2009
  5. 5. tables table name column column column Thursday, 03 December 2009
  6. 6. tables CREATE TABLE employees ( ID INT NOT NULL, name VARCHAR(20), name table salary INT, column column column PRIMARY KEY (ID) ) Thursday, 03 December 2009
  7. 7. relationship departments employees ID INT ID INT name varchar (10) name varchar (10) salary INT dept_ID INT Thursday, 03 December 2009
  8. 8. relationship departments employees ID INT ID INT name varchar (10) name varchar (10) salary INT 1 dept_ID INT Thursday, 03 December 2009
  9. 9. relationship departments employees ID INT ID INT name varchar (10) name varchar (10) salary INT 1 dept_ID INT many Thursday, 03 December 2009
  10. 10. relationship customer ID INT name varchar (10) sales cust_ID INT emp_ID INT s_date DATE amount DECIMAL employees ID INT name varchar (10) salary INT dept_ID INT Thursday, 03 December 2009
  11. 11. relationship customer ID INT name varchar (10) sales cust_ID INT emp_ID INT s_date DATE amount DECIMAL employees ID INT name varchar (10) 1 salary INT dept_ID INT Thursday, 03 December 2009
  12. 12. relationship customer many ID INT name varchar (10) sales cust_ID INT emp_ID INT s_date DATE amount DECIMAL employees ID INT name varchar (10) 1 salary INT dept_ID INT Thursday, 03 December 2009
  13. 13. relationship customer many ID INT many to name varchar (10) many sales cust_ID INT emp_ID INT s_date DATE amount DECIMAL employees ID INT name varchar (10) 1 salary INT dept_ID INT Thursday, 03 December 2009
  14. 14. Main actors • Production • Development • Stage • Test Thursday, 03 December 2009
  15. 15. Production database • You must have one Thursday, 03 December 2009
  16. 16. Development database • Where you create new things Thursday, 03 December 2009
  17. 17. Test database • Where you experiment crazy ideas Thursday, 03 December 2009
  18. 18. Stage database • Where you test before deploying to production Thursday, 03 December 2009
  19. 19. Schema maintenance actions • Reverse engineering • Forward engineering • Synchronization Thursday, 03 December 2009
  20. 20. Reverse Engineering Thursday, 03 December 2009
  21. 21. Reverse Engineering DDL dept_emp department dept_manager employees titles salaries Thursday, 03 December 2009
  22. 22. Reverse Engineering DDL dept_emp department dept_manager employees titles salaries Thursday, 03 December 2009
  23. 23. Reverse Engineering DDL dept_emp department dept_manager employees titles salaries Thursday, 03 December 2009
  24. 24. Forward Engineering Thursday, 03 December 2009
  25. 25. Forward Engineering Thursday, 03 December 2009
  26. 26. Forward Engineering Thursday, 03 December 2009
  27. 27. Forward Engineering DDL dept_emp department dept_manager employees titles salaries Thursday, 03 December 2009
  28. 28. Forward Engineering . ti ve ! truc G e s IN is d N g DDL A R n dept_emp W ee ri department g in dept_manager employees d en a r rw titles o salaries F Thursday, 03 December 2009
  29. 29. Synchronization Thursday, 03 December 2009
  30. 30. Synchronization Thursday, 03 December 2009
  31. 31. Synchronization Thursday, 03 December 2009
  32. 32. Synchronization Thursday, 03 December 2009
  33. 33. Synchronization Thursday, 03 December 2009
  34. 34. Synchronization Thursday, 03 December 2009
  35. 35. Synchronization Thursday, 03 December 2009
  36. 36. Synchronization Thursday, 03 December 2009
  37. 37. Synchronization Thursday, 03 December 2009
  38. 38. Synchronization Thursday, 03 December 2009
  39. 39. Synchronization Thursday, 03 December 2009
  40. 40. Synchronization Thursday, 03 December 2009
  41. 41. Synchronization Thursday, 03 December 2009
  42. 42. How it works yes Development OK? Production no no yes OK? Stage Test Thursday, 03 December 2009
  43. 43. How else it works Development Production • Partition adjustment • Dynamic schemas Test Stage • Hot fixes Thursday, 03 December 2009
  44. 44. What happens in between Development no OK? Test Thursday, 03 December 2009
  45. 45. What happens in between Development no What now? OK? Test Thursday, 03 December 2009
  46. 46. What happens in between Development no What now? Wrong schema here OK? Test Thursday, 03 December 2009
  47. 47. What happens in between Development no What now? Wrong schema here OK? REWIND? Test Thursday, 03 December 2009
  48. 48. Schema maintenance: how to 1. Poor man's way Thursday, 03 December 2009
  49. 49. How poor is the poor man? • only command line access • No Perl, PHP, or Python • Can't install anything • Command line access • Perl or Python available • Can install modules • Command line access • GUI • Can install everything Thursday, 03 December 2009
  50. 50. How poor is the poor man? ELY • only command line access EM R TR O EX PO • No Perl, PHP, or Python • Can't install anything • Command line access • Perl or Python available • Can install modules • Command line access • GUI • Can install everything Thursday, 03 December 2009
  51. 51. How poor is the poor man? ELY • only command line access EM R TR O EX PO • No Perl, PHP, or Python • Can't install anything • Command line access OR • Perl or Python available PO • Can install modules • Command line access • GUI • Can install everything Thursday, 03 December 2009
  52. 52. How poor is the poor man? ELY • only command line access EM R TR O EX PO • No Perl, PHP, or Python • Can't install anything • Command line access OR • Perl or Python available PO • Can install modules • Command line access RI CH • GUI • Can install everything Thursday, 03 December 2009
  53. 53. so, the extremely poor man's way ... HOST 1 HOST 2 Development Production Thursday, 03 December 2009
  54. 54. so, the extremely poor man's way ... HOST 1 HOST 2 get the Development Production schema TEXT FILE Thursday, 03 December 2009
  55. 55. so, the extremely poor man's way ... HOST 1 HOST 2 get the Development Production get the schema schema TEXT TEXT FILE FILE Thursday, 03 December 2009
  56. 56. so, the extremely poor man's way ... HOST 1 HOST 2 get the Development Production get the schema schema TEXT TEXT diff FILE FILE Thursday, 03 December 2009
  57. 57. so, the extremely poor man's way ... HOST 1 HOST 2 get the Development Production get the schema schema TEXT TEXT diff FILE FILE then … uh … figure out how to continue Thursday, 03 December 2009
  58. 58. the poor man's way ... HOST 1 HOST 2 Development Production get the get the schema schema TEXT diff TEXT FILE FILE Perl Script Thursday, 03 December 2009
  59. 59. the poor man's way ... HOST 1 HOST 2 Development Production get the get the schema schema TEXT diff TEXT FILE FILE Perl Script TELLS YOU WHAT TO DO Thursday, 03 December 2009
  60. 60. not so poor man's way ... HOST 1 HOST 2 Development Production DOES A LOT OF THINGS TELLS YOU WHAT TO DO Python Script http://schemasync.org Thursday, 03 December 2009
  61. 61. not so poor man's way ... HOST 1 HOST 2 Development Production DOES A LOT OF THINGS TELLS YOU WHAT TO DO Python Script http://schemasync.org WARNING: doesn't deal with partitions Thursday, 03 December 2009
  62. 62. The rich man http://aquafold.com Thursday, 03 December 2009
  63. 63. The rich man http://aquafold.com WARNING: doesn't deal with partitions Thursday, 03 December 2009
  64. 64. MySQL Workbench http://wb.mysql.com Thursday, 03 December 2009
  65. 65. MySQL Workbench http://wb.mysql.com Thursday, 03 December 2009
  66. 66. MySQL Workbench http://wb.mysql.com Thursday, 03 December 2009
  67. 67. Schema and model Thursday, 03 December 2009
  68. 68. Schema and model DDL dept_emp department dept_manager employees titles salaries Thursday, 03 December 2009
  69. 69. Schema and model DDL dept_emp department dept_manager employees titles salaries Thursday, 03 December 2009
  70. 70. Physical schema implemented in a specific DBMS Thursday, 03 December 2009
  71. 71. Physical schema DDL dept_emp department dept_manager implemented employees in a specific DBMS titles salaries Thursday, 03 December 2009
  72. 72. Conceptual model DBMS agnostic Thursday, 03 December 2009
  73. 73. Conceptual model DBMS agnostic Thursday, 03 December 2009
  74. 74. MySQL Workbench basics Thursday, 03 December 2009
  75. 75. Creating tables (1) Thursday, 03 December 2009
  76. 76. Creating tables (2) Thursday, 03 December 2009
  77. 77. Creating tables (3) Thursday, 03 December 2009
  78. 78. Creating tables (3) Thursday, 03 December 2009
  79. 79. Creating tables (4) Thursday, 03 December 2009
  80. 80. Creating tables (4) Thursday, 03 December 2009
  81. 81. Creating tables (5) Thursday, 03 December 2009
  82. 82. Creating tables (5) Thursday, 03 December 2009
  83. 83. database connections(1) Thursday, 03 December 2009
  84. 84. database connections(2) Thursday, 03 December 2009
  85. 85. Reverse engineering in the old world Thursday, 03 December 2009
  86. 86. Reverse engineering in the old world show create table departmentsG Create Table: CREATE TABLE `departments` ( `dept_id` int(10) unsigned NOT NULL, `department` char(30) NOT NULL, PRIMARY KEY (`dept_id`), KEY `department` (`department`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 1 row in set (0.00 sec) Thursday, 03 December 2009
  87. 87. Reverse engineering in the old world show create table departmentsG Create Table: CREATE TABLE `departments` ( `dept_id` int(10) unsigned NOT NULL, `department` char(30) NOT NULL, PRIMARY KEY (`dept_id`), KEY `department` (`department`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 1 row in set (0.00 sec) Thursday, 03 December 2009
  88. 88. Reverse engineering (1) Thursday, 03 December 2009
  89. 89. Reverse engineering (2) Thursday, 03 December 2009
  90. 90. Reverse engineering (3) Thursday, 03 December 2009
  91. 91. Reverse engineering (4) Thursday, 03 December 2009
  92. 92. Reverse engineering (5) Thursday, 03 December 2009
  93. 93. Reverse engineering (6) Thursday, 03 December 2009
  94. 94. Reverse engineering (7) Thursday, 03 December 2009
  95. 95. Reverse engineering (8) Thursday, 03 December 2009
  96. 96. Reverse engineering (9) Thursday, 03 December 2009
  97. 97. Reverse engineering (10) Thursday, 03 December 2009
  98. 98. forward engineering in the old world mysqldump --host=development -B --no-data crosstab > crosstab.sql mysql --host=stage < crosstab.sql Thursday, 03 December 2009
  99. 99. Forward engineering (1) Thursday, 03 December 2009
  100. 100. Forward engineering (2) Thursday, 03 December 2009
  101. 101. Forward engineering (3) Thursday, 03 December 2009
  102. 102. Forward engineering (4) Thursday, 03 December 2009
  103. 103. synchronization in the old world Thursday, 03 December 2009
  104. 104. Synchronization (1) Thursday, 03 December 2009
  105. 105. Synchronization (1) Thursday, 03 December 2009
  106. 106. Synchronization (2) Thursday, 03 December 2009
  107. 107. Synchronization (3) Thursday, 03 December 2009
  108. 108. Synchronization (4) Thursday, 03 December 2009
  109. 109. Synchronization (5) Thursday, 03 December 2009
  110. 110. Synchronization (6) Thursday, 03 December 2009
  111. 111. More goodies • MySQL Workbench 5.2 (Beta) - live demo Thursday, 03 December 2009
  112. 112. Thanks Let's talk! Thursday, 03 December 2009
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×