本文目錄一覽:
mysql中同時查詢兩個資料庫中的數據
1、打開php的編輯器sublime,新建一個文件,寫上注釋內容。
2、新建一個函數chaxun。
3、連接資料庫,填寫資料庫的用戶名,密碼,主機名以及要使用的資料庫。
4、填寫查詢的sql語句。select * from test1。
5、讀取查詢到的數據,我們這裡用到的函數是fetch_assoc來實現。
6、調用這個函數。
7、打開本地的伺服器,輸入網址進行訪問測試。
如何實現mysql不同資料庫之間的數據訪問
1.主上修改my.cnf文件:
server-id=1
log-bin=mysql-bin
2.從上修改配置文件 my.cnf
server-id=2
relay-log=relay-bin
read-only =1
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
#replicate-wild-do-table = tt.admin
replicate-wild-do-table = my_db.stu // 所要同步的資料庫的單個表
3. 創建 同步的用戶(主上)
grant replication client,replication slave on *.* to rep@’10.41.50.105′ identified by ‘root’;
4.同步到主庫(在從上操作)
change master to master_host=’10.41.50.80′,master_user=’rep’,master_password=’root’;
5.在從上驗證:
show slave status\G;
主從同步某些表
mysql資料庫如何用一條語句同時查多個資料庫
1. 子查詢方法
select *
from DB2.table2
where 欄位 in (select table1中相應欄位 from DB1.table1 where table1中相應欄位=相應值)
2. 左連接方法
select table2.*
from DB2.table2 left join DB1.table1
on table1.欄位 = table2.相應欄位
where table2.相應欄位 = 相應值;
2. 交叉連接方法
select table2.*
from DB2.table2, DB1.table1
where table1.欄位 = table2.相應欄位 and table2.相應欄位 = 相應值;
原創文章,作者:簡單一點,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/129304.html