首页 > 编程知识 正文

mysql访问多个数据库(java连接多个数据库)

时间:2023-12-11 12:29:21 阅读:314335 作者:KXAP

本文目录一览:

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 statusG;

主从同步某些表

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.相应字段 = 相应值;

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。