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.
The Ultimate Guide to Choosing WordPress Pros and Cons
MySQL Schema Maintenance
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. 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. 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
5. tables
table name
column column column
Thursday, 03 December 2009
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. relationship
departments employees
ID INT ID INT
name varchar (10) name varchar (10)
salary INT
dept_ID INT
Thursday, 03 December 2009
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. 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. 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. 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. 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. 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. Main actors
• Production
• Development
• Stage
• Test
Thursday, 03 December 2009
27. Forward Engineering
DDL
dept_emp
department
dept_manager
employees
titles
salaries
Thursday, 03 December 2009
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
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. 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. 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. 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. so, the extremely poor
man's way ...
HOST 1 HOST 2
Development Production
Thursday, 03 December 2009
54. so, the extremely poor
man's way ...
HOST 1 HOST 2
get the Development Production
schema
TEXT
FILE
Thursday, 03 December 2009
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. 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. 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. 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. 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. 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. 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. The rich man
http://aquafold.com
Thursday, 03 December 2009
63. The rich man
http://aquafold.com
WARNING: doesn't deal with partitions
Thursday, 03 December 2009
64. MySQL Workbench
http://wb.mysql.com
Thursday, 03 December 2009
65. MySQL Workbench
http://wb.mysql.com
Thursday, 03 December 2009
66. MySQL Workbench
http://wb.mysql.com
Thursday, 03 December 2009
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. 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
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