简体   繁体   English

在同一服务器中使用来自不同域的两个数据库

[英]Working with two databases from different domains within a same server

I have two domains. 我有两个域。

In domain A, I have a PHP web site and in domain B, I have Java Website. 在域A中,我有一个PHP网站,在域B中,我有Java网站。

Now I want to use both database from both site. 现在,我想同时使用两个站点的两个数据库。
How can I do that? 我怎样才能做到这一点? I am using MySql 5.7.17 我正在使用MySql 5.7.17

You could set up a third server dedicated to mySQL and share that database with the 2 web servers, or you can just run a mySQL database on each of those computers and use the IP address or domain name of them to connect to each other's server 您可以设置专用于mySQL的第三台服务器并与2台Web服务器共享该数据库,也可以只在每台计算机上运行一个mySQL数据库,并使用它们的IP地址或域名连接到彼此的服务器

Explanation: 说明:

You currently have a java website running and a php website running on one machine if i understand correctly. 如果我正确理解,您当前在一台机器上运行一个Java网站和一个php网站。

What you need to do is download mySQL, and go through the tutorial to get the server up and running https://dev.mysql.com/doc/mysql-getting-started/en/ 您需要做的是下载mySQL,并完成本教程以启动服务器并运行https://dev.mysql.com/doc/mysql-getting-started/en/

Then you need to download the mysql Java driver, and the mysql PHP driver 然后,您需要下载mysql Java驱动程序和mysql PHP驱动程序

Then you need to use the drivers to connect to the same mySQL server from the code, which would be on localhost if you are doing it all on one machine. 然后,您需要使用驱动程序从代码连接到相同的mySQL服务器,如果您要在一台计算机上完成所有操作,则该代码应位于localhost上。

MySQL is a server. MySQL是一台服务器。 It is its own thing, not a database like SQLite that you create in the java code or php code. 这是它自己的事情,而不是您在Java代码或php代码中创建的类似SQLite的数据库。 You create and set it up separately as it's own server, and then any other server can connect to it 您可以单独创建和设置它作为其自己的服务器,然后其他任何服务器都可以连接到它

You can open and close a mysql connection any time. 您可以随时打开和关闭mysql连接。

mysql_connect(server, username, password);

Do some stuff with one database, then you can use: 用一个数据库做一些事情,然后可以使用:

mysql_close();
mysql_connect(server2, username2, password2);

as many times as you like. 尽可能多的次数。

Or you can use resource links: 或者您可以使用资源链接:

$db1 = mysql_connect(server1, user1, passwd1);
$db2 = mysql_connect(server2, user2, passwd2);

But in this case, each mysql command needs to be referenced with the resource link: 但是在这种情况下,每个mysql命令都需要使用资源链接进行引用:

mysql_query(query, $db1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Java中将两个不同的Excel文件连接为同一服务器上的数据库? - How to connect two different excel files as databases on the same server in java? 从两个不同的数据库中检索相同DTO的信息 - Retrieve information for the same DTO from two different databases 具有相同数据的两个数据库,报告的时间不同 - Two databases with the same data, are reporting different times 在两个不同数据库中同时在两个表上进行事务处理 - Transaction on two tables at the same time in two different databases 如何比较两个不同数据库的数据? - How to compare data from two different databases? 同一服务器上同一EAR应用程序的多个副本具有不同的URL和数据库 - Multiple copies of the same EAR application on the same server with different URL and databases 如何在Windows上的安全网络中将两个域重定向到同一tomcat服务器 - how to redirect two domains to the same tomcat server in a secure network on windows 同一服务器上不同数据库的Java应用程序服务器连接池 - Java application server connection pooling for different databases on same server 使用jdbc查询两个数据库到sql服务器的同一实例 - using jdbc to query two databases to the same instance of sql server 从同一公司站点的不同域中获取Cookie - Getting cookies from different domains of same company's sites
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM