MySQL遠端表訪問設定

2022-08-16 10:33:11 字數 3147 閱讀 4704

mysql遠端表訪問設定

本博文**自          

---- 官網上的資訊

使用mysql federated儲存引擎,沒有對錶的本地資料檔案(比如,沒有.myd檔案)。取而代之地,乙個遠端資料庫儲存那些正常地應該在表中的資料。這使得mysql客戶端api來讀,刪除,更新和插入資料的使用成為必要。資料取回被通過select * from tbl_name sql語句來初始化。要讀這個結果,通過使用mysql_fetch_row() c api函式,行被一次取乙個,然後從select結果包中的列轉換成federated處理器期望的格式。

基本流程如下:

1.    sql呼叫被本地發布

2.    mysql處理器api (資料以處理器格式)

3.    mysql客戶端api (資料被轉換成sql呼叫)

4.    遠端資料庫-> mysql客戶端api

5.    轉換結果包(如果有的話)到處理器格式

6.    處理器 api -> 結果行或受行影響的對本地的計數  

使用federated表的步驟是非常簡單的。通常,你執行兩個伺服器,要麼在同乙個主機上,要麼在不同主機上。(乙個federated表使用其它被同一伺服器管理的表也是可能的。雖然只有極少的點要這麼做)。

首先,你必須在你想要用federated表訪問的遠端伺服器上有乙個表。假設,遠端的表在federated資料庫中並且被如下定義:

create table test_table (
id     int(20) not null auto_increment,
name   varchar(32) not null default '',
other  int(20) not null default '0',
primary key  (id),
key name (name),
key other_key (other)
)
engine=myisam
default charset=latin1;
engine表選項可能命名任何儲存引擎,該錶需要不是乙個myisam表。

接著,在本地伺服器上為訪問遠端表建立乙個federated表:

create table federated_table (
id     int(20) not null auto_increment,
name   varchar(32) not null default '',
other  int(20) not null default '0',
primary key  (id),
key name (name),
key other_key (other)
)
engine=federated
default charset=latin1
connection='mysql://root@remote_host:9306/federated/test_table';
注意: connection 替代 用在先前版本的mysql裡的comment)。

除了engine表選項應該是federated,並且connection表選項是給federated指明如何連線到遠端伺服器上的連線字串之外,這個表的結構必須完全與遠端表的結構相同。

federated引擎僅建立在已聯盟資料庫中的test_table.frm檔案。

遠端主機資訊指明本地伺服器要連線到的遠端伺服器,資料庫和表資訊指明哪乙個遠端表要被作為資料檔案來用。在這個例子中。遠端伺服器被指定來作為遠端主機在9306埠上執行,所以你要啟動伺服器,讓它監聽9306埠。

在connection選項中的連線字串的一般形式如下:

scheme://user_name[:password]@host_name[:port_num]/db_name/tbl_name
只有mysql在這一點被支援為scheme,密碼和埠號時可選的。

這裡有一些連線字串的例子:

connection='mysql://username:password@hostname:port/database/tablename'
connection='mysql://username@hostname/database/tablename'
connection='mysql://username:password@hostname/database/tablename'
為指定連線字串使用connection是非可選,並且在將來可能會改變。當你使用federated表的時候,要記得這個,因為這意味著當將來發生那種改變之時,可能被要求。

因為任何被用的密碼作為純文字被存在連線字串中,它可以被任何使對federated表使用show create table或show table status的使用者,或者在information_schema資料庫中查詢tables表的使用者看見。

federated支援及不支援的如下:

·         在第乙個版本中,遠端伺服器必須是乙個mysql伺服器。federated對其它資料庫引擎的支援可能會在將來被新增。

·         federated表指向的遠端表在你通過federated表訪問它之前必須存在。

·         乙個federated表指向另乙個federated表是可能的,但是你必須小心不要建立乙個迴圈。

·         沒有對事務的支援。

·         如果遠端表已經改變,對federated引擎而言是沒有辦法知道的。這個的原因是因為這個表必須象資料檔案一樣工作,除了資料庫其它任何都不會被寫入。如果有任何對遠端資料庫的改變,本地表中資料的完整性可能會被破壞。

·         federated儲存引擎支援select, insert, update, delete和索引。它不支援alter table, drop table或任何其它的資料定義語言語句。當前的實現不使用預先準備好的語句。

·         執行使用select, insert, update和delete,但不用handler。

·         federated表不能對查詢快取不起作用。

這些限制中的一些在federated處理機的將來版本可能被消除

mysql遠端表 MySQL遠端表訪問設定

遠端的表在federated資料庫中並且被如下定義 create table test table id int 20 not null auto increment,name varchar 32 not null default other int 20 not null default 0 p...

MySQL遠端表訪問設定

遠端的表在federated資料庫中並且被如下定義 create table test table id int 20 not null auto increment,name varchar 32 not null default other int 20 not null default 0 p...

MySQL 設定遠端訪問

mysql遠端訪問,也就是通過ip訪問mysql服務,mysql對於安全的要求是非常嚴格的,需要授權。1.本地訪問 sql grantallprivilegeson toadmin localhost identifiedby admin withgrantoption flushprivilege...