mysql FEDERATED存儲引擎的使用

這個存儲引擎相當於DB lINK,可以像訪問本地表一樣訪問遠程DB的表。而且可以直接看到表數據。表結構的文件放在本地DB,表存儲內容文件放在遠程,相當於調用遠程的表數據文件。

操作步驟:
1 window 修改my.ini文件。在最底下的
[mysqld]
port=3306
federated

添加federated,支持federated類型的數據引擎。默認是不開啓的。

重啓apache。

打開mysql console執行show engines;可以看到federated是啓用的了。

2 在本地DB中執行以下sql。

CREATE TABLE IF NOT EXISTS `tablename` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `appID` int(11) NOT NULL,
  `issueNo` varchar(100) DEFAULT NULL,
  `issueTitle` varchar(255) DEFAULT NULL,
  `issueKicker` varchar(255) DEFAULT NULL,
  `productID` varchar(255) NOT NULL,
  `publicationDate` datetime NOT NULL,
  `price` double NOT NULL,
  `description` varchar(500) DEFAULT NULL,
  `status` enum('pending','publishing','published') DEFAULT NULL,
  `updateTime` datetime NOT NULL,
  `updateUser` varchar(50) NOT NULL,
  `bscmsID` int(11) DEFAULT NULL,
  `filter` varchar(255) DEFAULT NULL,
  `portraitCoverID` int(11) DEFAULT NULL,
  `uploadCover` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `status` (`status`),
  KEY `appID` (`appID`),
  KEY `publicationDate` (`publicationDate`)
) ENGINE=FEDERATED  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1
CONNECTION='mysql://user:[email protected]:3306/dbname/tablename';

注意:密碼不能包含@否則會提示connection string的格式錯誤。
Suggested fix:
Allow the @ character to be escaped, or at least annotate this in the docs (I imagine other chars will also cause a problem, such as / and :.  Perhaps the connection string could be specified as: "mysql://'username':'password'@'hostname.tld'/db/table"?

參考:http://bugs.mysql.com/bug.php?id=14810

猜你喜欢

转载自lhdst-163-com.iteye.com/blog/2145476
今日推荐