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

Print 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

Access 2013 For Dummies Access 2013 For Dummies
March 2013
$24.99 USD

Advertisement
Sign up today to receive special discounts,
product alerts, and news from O'Reilly.
Privacy Policy >
View Sample Newsletter >
  • Youtube
  • http://www.youtube.com/OreillyMedia
  • Twitter
  • Subscribe
  • View All RSS Feeds >
O'Reilly Media

800-889-8969 or 707-827-7019
Monday-Friday 7:30am-5pm PT
©2011, O'Reilly Media, Inc.
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
  • About O'Reilly
  • Academic Solutions
  • Contacts
  • Customer Service
  • Careers
  • Press Room
  • Privacy Policy
  • Terms of Service
  • Writing for O'Reilly
  • Community
  • Authors
  • Forums
  • Membership
  • Newsletters
  • RSS Feeds
  • User Groups
  • Partner Sites
  • makezine.com
  • makerfaire.com
  • craftzine.com
  • igniteshow.com
  • PayPal Developer Zone
  • O'Reilly Insights on Forbes.com