O'Reilly Databases

oreilly.comSafari Books Online.Conferences.

We've expanded our coverage and improved our search! Search for all things Database across O'Reilly!

Search Search Tips

advertisement
AddThis Social Bookmark Button

Listen Print Discuss Subscribe to Databases Subscribe to Newsletters

MySQL Federated Tables: The Missing Manual
Pages: 1, 2, 3, 4, 5

Creating Federated Tables

Your first task is to create two simple tables on server1, one with a key and one without. The reason for these two tables will become apparent later.



create database if not exists test;
use test;

drop table if exists tkey;
create table tkey ( 
    id int not null auto_increment primary key, 
    word varchar(30) not null, 
    key (word)
    );

drop table if exists tnokey;
create table tnokey ( 
    id int not null primary key, 
    word varchar(30) not null
    );

load data local infile '/usr/share/dict/words'
into table tkey (word);

insert into tnokey select * from tkey;

select count(*) from tkey;
select count(*) from tnokey;

Save this script to fed1.mysql and feed it to server1:

$ ~/server1/use.sh -t < fed1.mysql
+----------+
| count(*) |
+----------+
|   518584 |
+----------+
+----------+
| count(*) |
+----------+
|   518584 |
+----------+

(These numbers may be different in your system, depending on the size of your dictionary.)

On server2, create two federated tables that point to the ones just built on server1.

drop database if exists test;
create database if not exists test;
use test;

drop table if exists tkey_fed;
create table tkey_fed ( 
    id int not null auto_increment primary key, 
    word varchar(30) not null, 
    key (word)
)
engine=federated 
connection='mysql://server2usr:datacharmer@127.0.0.1:5001/test/tkey';

drop table if exists tnokey_fed;
create table tnokey_fed ( 
    id int not null primary key, 
    word varchar(30) not null
)
engine=federated 
connection='mysql://server2usr:datacharmer@127.0.0.1:5001/test/tnokey';

Save this to fed2.mysql and load it:

$ ~/server2/use.sh -t < fed2.mysql

If you don't get any output, your federated tables were created without problems. If you get any errors, go back to the previous section and make sure that you have done everything, including creating the appropriate user on server1.

Pages: 1, 2, 3, 4, 5

Next Pagearrow




Tagged Articles

Post to del.icio.us

This article has been tagged:

mysql

Articles that share the tag mysql:

MySQL FULLTEXT Searching (155 tags)

Live Backups of MySQL Using Replication (152 tags)

Advanced MySQL Replication Techniques (125 tags)

Ten MySQL Best Practices (59 tags)

Rolling with Ruby on Rails (56 tags)

View All

cluster

Articles that share the tag cluster:

Advanced MySQL Replication Techniques (38 tags)

MySQL Federated Tables: The Missing Manual (9 tags)

Session Replication in Tomcat 5 Clusters, Part 2 (8 tags)

Improving Network Reliability with Keepalived (6 tags)

Ten Tips for Building Your First High-Performance Cluster (5 tags)

View All

reference

Articles that share the tag reference:

What Is Web 2.0 (328 tags)

Rolling with Ruby on Rails (116 tags)

Top Ten Mac OS X Tips for Unix Geeks (113 tags)

Very Dynamic Web Interfaces (39 tags)

Top Ten Digital Photography Tips (36 tags)

View All

federated

Articles that share the tag federated:

MySQL Federated Tables: The Missing Manual (7 tags)

SAML 2: The Building Blocks of Federated Identity (6 tags)

View All

documentation

Articles that share the tag documentation:

Rethinking Community Documentation (20 tags)

Design by Wiki (14 tags)

Using NDoc: Adding World-Class Documentation to Your .NET Components (13 tags)

MySQL Federated Tables: The Missing Manual (6 tags)

Best Windows Admin Downloads (4 tags)

View All

Sponsored Resources

  • Inside Lightroom

Related to this Article

MySQL Stored Procedure Programming MySQL Stored Procedure Programming
by Guy Harrison , Steven Feuerstein
March 2006
$44.99 USD

Understanding Oracle Clinical Understanding Oracle Clinical
by Joan M. Johnson
May 2007
$9.99 USD

Advertisement
O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
O'Reilly FYI
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com